Итак, Custom Walkers немного боли, чтобы работать, пока вы не поймете их.
Следующий пользовательский код ходока должен предоставить вам то, что вам нужно. Добавьте к этому functions.php
файл вашей темы:
class Custom_Button_Walker extends Walker_Nav_Menu {
// We only care about the "end level" part of the menu, where closing </ul> tags are generated
public function end_lvl(&$output, $depth = 0, $args = array()) {
// This is from WP core code
$indent = str_repeat("\t", $depth);
// This line ensures we only add it on the proper level
$button = (0 == $depth) ? "{$indent}<button type=\"button\">Click Me!</button>\n" : '';
// This line is modified to include the button markup
$output .= "{$indent}</ul>\n{$button}";
}
}
Чтобы использовать пользовательский ходок, измените wp_nav_menu
вызов следующим образом:
wp_nav_menu(array(
'theme_location' => 'main_menu',
'items_wrap' =>'%3$s',
'container' => FALSE,
'walker' => new Custom_Button_Walker()
));
Вы, вероятно, придется создать свой собственный [Menu Walker Class] (https: //www.smashingmagazine.com/2015/10/customize-tree-like-data-structures-wordpress-walker-class/). То, что вы просите, на самом деле не является тривиальной задачей. –