I'm trying to add a menu using a custom walker class into a page or post body and settled on using a shortcode. I don't have to use a shortcode, but I do have to embed the menu into the central portion of page/post content, and the menu must use a custom walker.
While questions like this one: https://wordpress.stackexchange.com/a/293006/67420 have a working method to generally embed a menu inside page content, trying to extend that to also pass a custom walker does fail, with this warning:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'new wp_bootstrap_navwalker()' not found in /.../site/wp-includes/nav-menu-template.php on line 580
This menu, using this same custom walker class, runs fine when called regularly in the header. In this certain case, I must insert the main menu into the central portion of a certain page's content, instead (and so it's not called in that page's header). Also, I've tried to explicitly include the class as suggested below by @Antti Koskinen.
Here's my shortcode:
[menu container="div" container_id="main-nav" container_class="collapse navbar-collapse justify-content-center" menu_id="false" menu_class="navbar-nav" depth="3" fallback_cb="wp_bootstrap_navwalker::fallback" walker="new wp_bootstrap_navwalker()"]
And here's my custom shortcode function:
add_shortcode( 'menu', 'se_menu_shortcode' );
function se_menu_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'container' => null,
'container_id' => null,
'container_class' => null,
'menu_id' => null,
'menu_class' => null,
'depth' => null,
'fallback_cb' => null,
'walker' => null
), $atts ) );
return wp_nav_menu( array(
'container' => $container,
'container_id' => $container_id,
'container_class' => $container_class,
'menu_id' => $menu_id,
'menu_class' => $menu_class,
'depth' => $depth,
'fallback_cb' => $fallback_cb,
'walker' => $walker,
'echo' => false
) );
}
Appreciate any help!