Here’s the default usage of wp_nav_menu()
:
<?php
$defaults = array(
'theme_location' => ,
'menu' => ,
'container' => 'div',
'container_class' => 'menu-{menu slug}-container',
'container_id' => ,
'menu_class' => 'menu',
'menu_id' => ,
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => ,
'after' => ,
'link_before' => ,
'link_after' => ,
'items_wrap' => '<ul id=\"%1$s\" class=\"%2$s\">%3$s</ul>',
'depth' => 0,
'walker' =>
);
?>
Notice that the default fallback for wp_nav_menu()
is wp_page_menu(), for which the defaults are:
<?php
$args = array(
'sort_column' => 'menu_order, post_title',
'menu_class' => 'menu',
'include' => '',
'exclude' => '',
'echo' => true,
'show_home' => false,
'link_before' => '',
'link_after' => ''
);
?>
These should produce mostly the same output, with the same set of pages. However, if you need more specific control, you have a couple options:
-
Assign a custom callback here:
‘fallback_cb’ => ‘mytheme_wp_nav_menu_cb’
…and then, define:
function mytheme_wp_nav_menu_cb() { // Output whatever menu you want here }
…so that you override
wp_page_menu()
-
Wrap your
wp_nav_menu()
call in ahas_nav_menu()
conditional:if ( has_nav_menu( 'my_theme_top_menu' ) ) { // User has applied a custom menu // to the my_theme_top_menu location; // output it wp_nav_menu( array( 'theme_location' => 'my_theme_top_menu') ); } else { // User has NOT applied a custom menu; // Do something else }
…in the
else
statement, you can do whatever.