[Resolved] wp_nav_menu() fallback not receiving vars
I developed a custom walker class to implement the Bootstrap 3.0 menu structure so menus can be edited using the WordPress menu editor.
Everything works great except for the
$fallback_cbwhich is used by default when the theme is installed. I read in the codex that
(string) (optional) If the menu doesn’t exist, the fallback function to use. Set to false for no fallback. Note: Passes $args to the custom function.
The issue seems to be that the wp_page_menu function is not receiving the $args from the
Here is my current
<?php wp_nav_menu( array( 'menu' => 'primary', 'theme_location' => 'primary', 'depth' => 2, 'container' => false, 'menu_class' => 'nav navbar-nav', 'fallback_cb' => 'wp_page_menu', 'walker' => new wp_bootstrap_navwalker()) ); ?>
Can anyone offer some insight into how I might resolve this issue?
The idea with the
fallback_cbis that you set up your own fallback function – which may (or may not) make use of wp_page_menu().
I definitely understand that, is guess the question is
fallback_cbis undefined and defaults to
wp_page_menuis there any way to pass the defined
wp_nav_menuvars over to
From what I recall, wp_nav_menu() uses slightly different parameters to wp_page_menu(). So I’d guess that there no easy way of simply passing them from one function to the other.
It is true that
wp_page_menu()uses different parameters, but any arguments you supply to
wp_nav_menu()will be passed to the ‘fallback_cb’ function. Whether your ‘fallback_cb’ function or
wp_page_menu()can make use of these arguments is another story.
The key line in
wp_nav_menu()source code is:
call_user_func( $args->fallback_cb, (array) $args );
$argsis the merge of passed and default arguments, so you can see all arguments are passed to the ‘fallback_cb’ function. If this does not appear to be happening, it could be the
wp_page_menu()does not know how to use a particular argument, but the argument is being passed none the less.
- The topic ‘[Resolved] wp_nav_menu() fallback not receiving vars’ is closed to new replies.