Home › Forums › Back End › Menu-item not getting active class › Reply To: Menu-item not getting active class
November 18, 2014 at 2:37 pm
#188647
nichlas
Participant
Thanks @Alen!
I found this code in the last comment of the page that you linked to:
// Add class to current-menu-items
function custom_active_item_classes($classes = array(), $menu_item = false){
global $post;
$classes[] = ($menu_item->url == get_post_type_archive_link($post->post_type)) ? 'current-menu-item active' : '';
return $classes;
}
add_filter( 'nav_menu_css_class', 'custom_active_item_classes', 10, 2 );
Works like a charm! Thank you so much :)