0

I have problems with wordpress menu level classes.

<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>

this is the code i used to generate my menu,

First level menu id is

ul id="menu-home"

second level class is

ul class="sub-menu"

but my third level menu also has same class as second level

ul class="sub-menu"

is there any way to change the class of third level or some other solution???

please help.. thankyou

0

This will add class sub-menu-0, sub-menu-1 and so on depending upon their depth.

//This will go in functions.php file
class wpse61220_submenu_class extends Walker_Nav_Menu {
  function start_lvl(&$output, $depth) {
    $indent = str_repeat("\t", $depth);
    $output .= "\n$indent<ul class=\"sub-menu-".$depth."\">\n";
  }
}

//  Usage -
//  wp_nav_menu( array('walker' => new wpse61220_submenu_class() ) );

Reference - function wp_nav_menu()

0

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.