Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Custom Post type and WP Nav menus – Active State Reply To: Custom Post type and WP Nav menus – Active State

#171701
natebeaty
Participant

This was very handy, thanks for posting. I did streamline it a bit:

// custom nav highlighting for various pages
function fb_custom_nav_highlights($classes) {
  if (is_singular('video') && in_array('nav-watch-now', $classes)) {
    $classes[] = 'current-menu-item';
  } elseif (is_singular('post') && in_array('nav-whats-new', $classes)) {
    $classes[] = 'current-menu-item';
  }
  return $classes;
}
if (!is_admin()) { add_filter('nav_menu_css_class', 'fb_custom_nav_highlights'); }