0

I have a nav menu with a depth of 2.

wp_nav_menu( array( 'theme_location' => 'primary_navigation',
                    'depth'          => 2
) );

When I am active on a page in the nav menu that has no children, that li menu item has active appended. However, when the menu item has children, has-children is appended, but no 'active' or even a related class name.

<ul id="menu-main-top-navigation">
    <li class="parent1"></li>
    <li class="has-dropdown not-click">
        <ul class="dropdown">
            <li class="child1"></li>
            <li class="child2"></li>
        </ul>
    </li>
    <li class="parent3"></li>
    <li class="parent4"></li>
    <li class="active parent5"></li>
    <li class="parent6"></li>
</ul>

In this case I am the page relating to menu item 'parent5'. This is fine. When I navigate to what is meant to be 'parent2', the class name is replaced completely with 'has-dropdown' so there is no differing class name or 'active'.

How can I fix this. Even to remove the JQuery in this case.

1

Can you add the complete output code for the navigation menu. The code you pasted seems to be a stripped version. Moreover, WordPress adds 'current_page_item' class to the list item if it is currently being viewed.

For more info, check this WordPress documentation on classes added to Navigation menu items.

  • Thank-you, it seems this is foundation.js functionality which the site has been built with – myol Jun 9 '15 at 11:30
0

Thanks to mstoic for pointing out that this is not default WP functionality. This ended up being an unhelpful feature (for me) used in a WordPress stack.

I found the offending line and commented it out.

  $output .= "\n<ul class=\"dropdown\">\n";
  }

  function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
    $item_html = '';
    parent::start_el($item_html, $item, $depth, $args);

    if ($item->is_dropdown && ($depth === 0)) {
      //$item_html = str_replace('<li', '<li class="has-dropdown not-click"', $item_html);
    ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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