I'm creating a custom menu with wp_nav_menu. I want to add different classes on menu and submenu which are coming under different li, but unable to find a solution. Can anyone help me to figure out this question. I am sharing the HTML part which I am trying to convert for making menu dynamic.

<li><a href="#">Home </a></li>
<li class="menu-dropdown"><a href="#">Supplies <i class="ion-ios-arrow-down"></i></a>
    <ul class="sub-menu">
        <li><a href="#">Chemicals</a></li>
        <li><a href="#">Food</a></li>
<li class="menu-dropdown"><a href="#">More <i class="ion-ios-arrow-down"></i></a>
    <ul class="sub-menu">
        <li class="menu-dropdown position-static"><a href="#">Supplies <i class="ion-ios-arrow-down"></i></a>
            <ul class="sub-menu sub-menu-2">
                <li><a href="#">All</a></li>
                <li><a href="#">Chemicals</a></li>
        <li><a href="#">Blogs </a></li>
        <li><a href="#">Contact Us </a></li>

Code that I am using in my site-nav.php is

$args = array(
    'menu' => 'primary-menu',
    'container' => '',
    'depth' => 3,
    'fallback_cb'  => false,
    'add_li_class' => 'menu-dropdown',

Please help.

  • Can someone help me in fixing this issue please. Jul 2, 2021 at 15:32

1 Answer 1


add_li_class isn't valid arg for wp_nav_menu

Try this in your functions.php

add_filter( 'nav_menu_css_class', 'add_my_class_to_nav_menu', 10, 2 );
function add_my_class_to_nav_menu( $classes, $item ){
    $classes[] = 'menu-dropdown';
    return $classes;
  • Thanks for your reply but i have added add_li_class with another function, this is not an issue, main issue is a class is adding additionally in first ul which is not required if you look over image it's clarify better. ibb.co/sFwMwMZ Jun 30, 2021 at 18:35

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.