I need the WordPress menu to include the ‘current-menu-ancestor’ class to reflect that site is currently in the recipe section. Supposing I have a recipe custom post type. I have the following code in my functions.php but it’s not working:
function add_active_item_classes($classes = array(), $menu_item = false){
if ( get_post_type() == 'recipe' && $menu_item->title == 'Recipes') {
$classes[] = 'current-menu-ancestor';
return $menuclasses;
}
}
Also I don’t know what filter hooks I will use to have this effect? Thanks for your suggestion and assistance.
I have the complete answers here: https://wordpress.stackexchange.com/questions/77931/how-to-include-the-current-menu-ancestor-class-on-a-custom-post-type-menu-in-w/78302#78302
There were issues with the variables that is why it is not working properly. Hope this will be helpful to anyone searching for similar solution.