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

  • kasiapl


    I am still experiencing this issue:

    6.1.1 was supposed to fix the bug logged here:

    but this is still not working for me with 6.1.1

    This is my wp_nav_menu call:

          '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.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘wp_nav_menu not adding menu-item-has-children class to list items’ is closed to new replies.