Last active
December 14, 2015 22:58
-
-
Save SideQuestDIY/5161892 to your computer and use it in GitHub Desktop.
A quick explanation of how to use the WordPress wp_nav_menu's fallback_cb variable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
wp_nav_menu( array( | |
'menu' => 'top_menu', | |
'depth' => 2, | |
'container' => false, | |
'menu_class' => 'nav', | |
//Process nav menu using our custom nav walker | |
'walker' => new twitter_bootstrap_nav_walker()), | |
'fallback_cb' => 'wp_page_menu', // No menu available: will display all pages in menu | |
//'fallback_cb' => '__return_false', // No menu available: no output. | |
); | |
?> |
I think the 'fallback_cb' must be set inside the array, the code above is set outside array, look
new twitter_bootstrap_nav_walker()),
Thanks :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In order to prevent an error when no menu is defined you must declare a
fallback_cb
variable inside your themeswp_nav_menu
array. You have two options for alternate display that come with wordpress.This will populate the menu with your WordPress pages if no menu is assigned in the WordPress admin.
This will return nothing if no menu is assigned in the WordPress admin.