Skip to content

Instantly share code, notes, and snippets.

@PlanBrewski
Last active December 14, 2015 22:58
Show Gist options
  • Save PlanBrewski/5161892 to your computer and use it in GitHub Desktop.
Save PlanBrewski/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.
<?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.
);
?>
@PlanBrewski
Copy link
Author

In order to prevent an error when no menu is defined you must declare a fallback_cb variable inside your themes wp_nav_menu array. You have two options for alternate display that come with wordpress.

'fallback_cb' => 'wp_page_menu'

This will populate the menu with your WordPress pages if no menu is assigned in the WordPress admin.

'fallback_cb' => '__return_false'

This will return nothing if no menu is assigned in the WordPress admin.

@imamherlambang
Copy link

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