Support » Fixing WordPress » wp_nav_menu not adding menu-item-has-children class to list items

  • I am still experiencing this issue:

    https://wordpress.org/support/topic/wp-6-1-rc3-menu-item-has-children-class-is-not-being-applied-correctly/

    6.1.1 was supposed to fix the bug logged here:

    https://core.trac.wordpress.org/changeset/54478

    but this is still not working for me with 6.1.1

    This is my wp_nav_menu call:

    wp_nav_menu(array(
          'theme_location' => 'site-navigation-and-search__main-navigation',
          'container' => null,
          'menu_id' => 'main-navigation__list',
          'menu_class' => 'site-navigation__main-navigation__list',
          'walker' => new MainNavigationWalker(),
          'depth' => 1
    ));

    The full structure of the menu being called is 2 levels deep, with one child underneath each of the top level items. I am using a custom walker to retrieve the parent level items (hence depth 1), and then the array parameters of the pages present in the child items are used to build out a megamenu panel that opens on hover. The custom walker relies on whether a top level item has the class menu-item-has-children in order to apply a custom class to the top level list item that controls both its styling and its child panel, as well as additional outputs to build the child panel. When that class isn’t detected, the walker defaults to a plain <li> item with no sub-content.

    if( (0 === $depth) && array_search('menu-item-has-children', $item->classes)) {
       $output .= '<li class="menu-item-li">';

    When depth is set to 1, the $item->classes array is no longer returning menu-item-has-children as a class, which the rest of the logic and output of the waker depends on. I’m hoping someone has a suggestion on how to resolve this.

  • You must be logged in to reply to this topic.