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 customised my menu in wordpress by extending the Nav_Menu_Walker class and now i cannot figure it out how could i add a class at a specific ul element. I have this function which adds classes by depth:

function start_lvl(&$output, $depth) {
 $indent = str_repeat("\t", $depth);
 if ($depth >= 1)
    $output .= "\n$indent<ul class=\"subsubmenu\">\n";
    $output .= "\n$indent<ul class=\"submenu\">\n";


When the $depth is 0 i would like to add a different class at the third element from $depth =0 rather than "submenu".

Could you please provide me some suggestions ?

share|improve this question
I am not I understand: You want different classes for depth 0, 1 or many? Or on the third submenu with a depth == 0? – toscho Oct 12 '12 at 9:39
At the level where the $depth == 0 i have like 4 columns. What i meant was at the 3 ( third) column to have a different class. – GigiBecali Oct 12 '12 at 11:06
up vote 1 down vote accepted

Count the level 0 elements in a static variable in the method and add an extra class if you hit the third. Sample code, not tested:

function start_lvl(&$output, $depth) {
    static $column = 1;
    $indent = str_repeat("\t", $depth);
    if ($depth > 0)
        $output .= "\n$indent<ul class='subsubmenu'>\n";
        $column += 1;
        $extra = 3 === $column ? ' third-column' : '';
        $output .= "\n$indent<ul class='submenu$extra'>\n";
share|improve this answer
Thank you for open up my mind ! Great answer ! – GigiBecali Oct 12 '12 at 11:43

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.