start_lvl Ignored in Custom walker_nav_menu

This is my first project involving WordPress and I’ve got stuck trying to create a custom walker for a footer menu.

I basically want to change the menu from the <ul> <li></li> </ul> structure to a <p> <span></span> </p> structure.

The menu and stuff is displaying file and I have been able to adjust the start_el and end_el functions without issue so I now get this:

<ul> <span>*link*</span> <span>*link*</span> </ul>

Which is obviously half way there, I have written the start_lvl() and end_lvl() tags as shown below but they are ignored by WordPress – nothing I put in them (even die()) is executed (which is a bit suspicious) but I know the class is being called because of the start_el() function.

function start_lvl(&$output, $depth = 0, $args = array()) {
    $output = "\n<p class=\"sub-menu\">\n";
}

function end_lvl(&$output, $depth = 0, $args = array()) {
    $output .= "\n</p>\n";
}

Does anyone know why this is happening – have I missed something really obvious!?

I am running the latest version of WordPress on Apache with PHP 5.3.6 if it helps.

Thanks in advance,

Felix 🙂

3 s
3

Your my_extended_walker class is OK, but when you call the wp_nav_menu function use the items_wrap parameter.

wp_nav_menu( array( 'items_wrap' => '<p>%3$s</p>', 'walker'=>new my_extended_walker() ) );

The start_lvl is used for children elements.

Leave a Comment