I just realized the fallback doesn’t work for my project when a custom menu doesn’t exist. I can’t figure out what I am missing. Here is the code that displays the nav menu:
$menu = wp_nav_menu(
array(
'menu_class' => 'reset sf-menu',
'container_id'=>'nav',
'echo'=>0
)
);
$menu = str_replace("\n", "", $menu);
$menu = str_replace("\r", "", $menu);
$menu = str_replace("\t", "", $menu);
echo $menu;
here is the test site: http://brainbuzzmedia.com/themes/amplify/styles/charcoal/
You’ve not added a fallback_cb
key to the argument array. You also need to add a theme_location
key:
php start $menu = wp_nav_menu(
array(
'menu_class' => 'reset sf-menu',
'container_id'=>'nav',
'echo'=>0,
'fallback_cb' => 'mytheme_fallback_function' // ADD ME!!!
'theme_location' => `location_name` // ADD ME, AS DEFINED IN register_nav_menu()
)
);
$menu = str_replace("\n", "", $menu);
$menu = str_replace("\r", "", $menu);
$menu = str_replace("\t", "", $menu);
echo $menu;
php end
Alternately, you could wrap your code in an if ( has_nav_menu( 'location_name' ) )
conditional:
if ( has_nav_menu( 'location_name' ) ) {
echo $menu;
} else {
// Do something else, like wp_list_pages() or wp_page_menu()
}