2
votes

Maybe I am thinking about this too much. Hopefully I am not. I would like to add a class dropdown-menu animated to all sub menus in the wp_nav_menu that are in a particular location without using a walker. I realise there is a filter for this called nav_menu_submenu_css_class but I am unable to determine the location of the menu. This is my code;

function mi_submenu_css( $classes, $args, $depth )
{
    print_r ($args); echo "JTGO";
    /*if ('header-menu' === $args->theme_location) {*/
        $display_depth = ($depth + 1);
        array_push($classes, 'dropdown-menu animated fadeOutUp menu-depth-' . $display_depth);
    /*}*/
    return $classes;
}

I expected $args to contain the menu location but comes back empty. You can see I have tried to print it out as an array.

1

1 Answers

2
votes

To solve the problem I had to specify the number of arguments in my filter. So instead of having;

add_filter( 'nav_menu_submenu_css_class', 'mi_submenu_css' );

I changed it to;

add_filter( 'nav_menu_submenu_css_class', 'mi_submenu_css', 10, 4 );