WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Your Answer


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.