0

Hey Folks I trying to customize a wordpress walker class to add custom classes to navigation level. Essentially there will be 3 levels of navigation.

Here's the code:

<ul class="rd-navbar-nav"> <li class="rd-nav-item active"><a class="rd-nav-link" href="#">Home</a></li> <li class="rd-nav-item rd-navbar--has-dropdown rd-navbar-submenu"><a class="rd-nav-link" href="#">Activities</a></span> <ul class="rd-menu rd-navbar-dropdown"> <li class="rd-dropdown-item"><a class="rd-dropdown-link" href="#">Classic Blog</a></li> <li class="rd-dropdown-item"><a class="rd-dropdown-link" href="#">Blog Post</a></li> </ul> </li> </ul>

1
  • Did you manage the modification of the menu?
    – nmr
    Commented Aug 24, 2018 at 8:47

1 Answer 1

0

If you want change only CSS classes, you can use filters nav_menu_submenu_css_class (for <ul> element, codex) and nav_menu_css_class (for <li>, codex).

Example of usage:

add_filter('nav_menu_css_class' , 'special_menu_item_class' , 20 , 4);

function special_menu_item_class($classes, $item, $args, $depth) {
    // add or replace classes
    $classes[] = 'rd-nav-item';
    if ($args->has_children) {
        $classes[] = 'rd-navbar--has-dropdown';
    }
    return $classes;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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