single-event page and current menu item on main nav
-
I created a single-event.php page but the events menu on my main nav doesn’t show the
current-menu-item
class so I added this bit of code in my functions.php file which kind of got it working..`function my_special_nav_class( $classes, $item ) {
if ( is_single() && $item->title == ‘Events’ ) {
$classes[] = ‘current-page-ancestor’;
}
return $classes;
}add_filter( ‘nav_menu_css_class’, ‘my_special_nav_class’, 10, 2 );`
however since the above function is finding out whether the page is using the single template therefore all my other pages that is also using the single template file is adding the
.current-page-ancestor
class to it as well. How can I add a custom class on my
main nav to show the selected state on this page.
- The topic ‘single-event page and current menu item on main nav’ is closed to new replies.