Complete the code to start a custom walker class by extending the correct WordPress class.
class My_Custom_Walker extends [1] { // Custom walker code here }
The Walker_Nav_Menu class is the base class to extend when creating a custom navigation menu walker in WordPress.
Complete the method signature to override the start of a menu item output.
public function [1](&\$output, \$item, \$depth = 0, \$args = null, \$id = 0) { // Custom code here }
end_el instead of start_el.The start_el method is used to output the start of each menu item in a custom walker.
Fix the error in the method name to properly close a submenu level.
public function [1](&\$output, \$depth = 0, \$args = null) { \$indent = str_repeat("\t", \$depth); \$output .= "\n" . \$indent . "</ul>\n"; }
start_lvl instead of end_lvl.The end_lvl method is used to output the closing tags for submenu levels in a custom walker.
Fill both blanks to add a CSS class to the menu item and output the link tag.
public function start_el(&\$output, \$item, \$depth = 0, \$args = null, \$id = 0) { \$classes = empty(\$item->classes) ? array() : (array) \$item->classes; \$classes[] = [1]; \$class_names = join(' ', array_filter(\$classes)); \$output .= '<li class="' . esc_attr(\$class_names) . '">'; \$output .= '<a href="' . esc_url(\$item->url) . '">' . [2] . '</a>'; }
Adding a custom CSS class helps style the menu item. Using esc_html(\$item->title) safely outputs the menu item title inside the link.
Fill both blanks to create a submenu wrapper with a custom class and indentation.
public function start_lvl(&\$output, \$depth = 0, \$args = null) { \$indent = str_repeat("\t", [1]); \$classes = array([2]); \$class_names = implode(' ', \$classes); \$output .= "\n" . \$indent . '<ul class="' . esc_attr(\$class_names) . '">\n'; }
The indentation uses the current depth to align submenu levels. The classes array includes a custom class string. The class names are joined with spaces.