Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

This is the final working code:

function additional_active_item_classes($classes = array(), $menu_item = false){
global $wp_query;

if(in_array('current-menu-item', $menu_item->classes)){
    $classes[] = 'current-menu-item';

if ( $menu_item->post_name == 'product' && is_post_type_archive('product') ) {
    $classes[] = 'current-menu-item';

if ( $menu_item->post_name == 'product' && is_singular('product') ) {
    $classes[] = 'current-menu-item';

return $classes;
add_filter( 'nav_menu_css_class', 'additional_active_item_classes', 10, 2 );

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.