Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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()

share|improve this answer
    
Thankyou... that worked... :) –  Hareesh Aug 8 '12 at 18:00
    
you're welcome.. :) –  amit Aug 8 '12 at 18:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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