我做了以下工作,如果你有许多帖子类型,可能会很长,但是请随意编辑:
/** Edit Nav Menu calsses **/
function custom_wp_nav_classes($classes, $item){
global $post;
$page_blog = get_option(\'page_for_posts\');
if(is_tax(\'my_taxonomy_name_here\') || is_singular(\'my_post_type_name_here\')){
/** Remove Active Class from Blog **/
if($item->object_id == $page_blog)
$classes = array_filter($classes, "remove_parent");
/** Page ID of what you want to be active **/
if($item->object_id == 12)
$classes[] = \'current_page_parent\';
}
return $classes;
}
add_filter(\'nav_menu_css_class\' , \'custom_wp_nav_classes\' , 10 , 2);
// Remove Active Class from Blog when viewing CPTs
function remove_parent($var){
if ($var == \'current_page_parent\' || $var == \'current-menu-item\' || $var == \'current-page-ancestor\') { return false; }
return true;
}