start_lvl on Walker is not working

list code sample

I’m creating a custom Walker to my menu, my code is like this:

<?php

class My_Walker extends Walker {
    function start_lvl( &$output, $depth = 0, $args = array() ) {
        $output .= "<nav>";
    }

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

    function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
        $output .= "<li>My Item</li>";  //This is just a sample <li>
    }
}

The start_el is working fine, but start_lvl and end_lvl is not working at all.

The rendered HTML is like this:

Why is my start_lvl and end_lvl not working?

Read more here:: start_lvl on Walker is not working

Leave a Reply

Your email address will not be published. Required fields are marked *