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

Home Forums Back End Menu-item not getting active class Reply To: Menu-item not getting active class


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 :)