Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jayseventwo/5449523 to your computer and use it in GitHub Desktop.
Save jayseventwo/5449523 to your computer and use it in GitHub Desktop.
Fix nav menu issues with custom post types. If, when you link to a custom post type in your nav menu, the blog page also highlights the nadd the following to your functions.php, where "menu-portfolio" is the name of the nav menu item you need to fix.
function fix_portfolio_parent($menu){
global $post;
if ( 'portfolio' == get_post_type() )
{
$menu = str_replace( 'current_page_parent', '', $menu ); // remove all current_page_parent classes
$menu = str_replace( 'menu-portfolio', 'current_page_parent menu-portfolio', $menu ); // add the current_page_parent class to the page you want
}
return $menu;
}
add_filter( 'nav_menu_css_class', 'fix_portfolio_parent', 0 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment