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'm creating a custom Walker based on Walker_Nav_Menu for a megamenu I'm working on and the issue I'm having is that it seems the tags I open on start_lvl are being automatically closed. Here's my code:

public function start_lvl( &$output, $depth = 0, $args = array() ) {
    $indent = str_repeat( "\t", $depth );
    $output .= "\n$indent<ul role=\"menu\" class=\" dropdown-menu\">\n";

            // Add specific tags only on first submenu
    if (0 == $depth) {

        $output .= "\n$indent<li>\n";
        $output .= "\n$indent<div class='yamm-content'>\n";

    }
}

And on my end_lvl I've got this:

public function end_lvl( &$output, $depth = 0, $args = array() ) {

    $indent = str_repeat("\t", $depth);
    $output .= "$indent</ul>\n";

    if (0 == $depth) {

        $output .= "$indent</div>\n";
        $output .= "$indent</li>\n";

    }
}

However with or without end_lvl I get this output:

<li>
    <div class="yamm-content"> </div>
</li>
<li>Menu item 1<li>
<li>Menu item 2<li> // These items should be inside the above div
...

I'm new to Walker but I thought that whatever I add to start_lvl would wrap the <li> tags. What am I missing?

PS: I have tried without the conditional if (0 == $depth) and the difference was only the above code was in every level rather than just on the first.

share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.