What does a walker menu mean?

Walker_Nav_Menu is the core class to handle navigation menus.
You can use it to handle your navigation menu, or you can create your own children class that extends this class.

If you decide to use your own class, then you must pass an instance as an argument when you use wp_nav_menu()

class myWalkerClass Extends \Walker_Nav_Menu {
 //overwrite any method as you see fit.
}

$args = [
  'container' => 'div',
  //...other arguments,
  'walker' => new myWalkerClass(),
];

wp_nav_menu( $args );

if you want to let the core class handle your nav menu, just dont pass it as an argument.

EDIT: Example of a child PHP class:

class myWalkerChildClass Extends \Walker_Nav_Menu {

  /*there are 4 methods that can be overwritten ( meaning that if you declare them here, you are using your own method, and if you dont declare them here, you are using the original method from Walker_Nav_Menu parent PHP class.*/


    /*please note that fore very method, $output is passed by reference, meaning you can modify $output directly in the method, and changes carry over to the next method until it is printed.*/

    function start_lvl(&$output, $depth, $args ) {

        $output .= "\n<ul>\n"; //here you are starting a new list,
    }

    function end_lvl(&$output, $depth, $args ) {
        $output .= "</ul>\n"; //here you are closing a list,
    }


    function start_el(&$output, $item, $depth, $args ) {
        $output. = "<li>".esc_attr($item->label); //here you are starting a new item within a list.
    }

    function end_el(&$output, $item, $depth, $args ) {
        $output .= "</li>\n"; //and finally closing the item
    }
}

}

for a more indepth tutorial, check here:

Leave a Comment