1

Does anyone know how to add a "active" class to the parent container menu in WordPress 4.1.1 ?

If an item of the menu has the "current-menu-item" class, I want to add "active" class to the parent container.

Example of what I need (the "active" class) :

<nav>
    <ul class="active">
        <li>Item 1</li>
        <li class="current-menu-item">Item 2</li>
        <li>Item 3</li>
    </ul>
</nav>

Thank you !

EDIT

It's a standard WP menu. Menu PHP :

$args = array(
    'theme_location'    =>  'main_menu',
    'fallback_cb'       =>  'wp_page_menu',
    'items_wrap'        =>  '<ul>%3$s</ul>'
);
$main_menu = wp_nav_menu($args);

Current HTML structure :

<nav>
    <ul>
        <li>Item 1</li>
        <li class="current-menu-item">Item 2</li>
        <li>Item 3</li>
    </ul>
</nav>
  • 1
    Is this a standard WordPress nav menu? Can you show us what you currently have rather than what you'd like? – Tom J Nowell Mar 13 '15 at 16:13
  • Yes it's a standard WP menu. I edited my post with others infos. Thx ! – Gabriel Mar 13 '15 at 16:31

Your Answer

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

Browse other questions tagged or ask your own question.