Alright so I’ve got two navigation menus that I’ve registered with my theme:
<?php
if ( function_exists('register_sidebar') )
register_sidebar();
add_theme_support( 'menus' );
if ( function_exists('register_nav_menu') ) {
register_nav_menu( 'primary_nav', 'Primary Navigation');
register_nav_menu( 'secondary_nav', 'Secondary Navigation');
}
?>
Functions.php
And then Beyond that I’ve got two places in my header where I display the navigation menus:
<!-- BEGIN: Navigation Menu primary_nav (Primary Navigation) -->
<?php
if(function_exists('wp_nav_menu'))
{
wp_nav_menu(
array(
'menu' => 'primary_nav',
'container' => '',
'depth' => 1,
'menu_id' => 'menu'
)
);
}
else
{
?>
<ul>
<?php wp_list_pages('title_li=&depth=1'); ?>
</ul>
<?php
}
?>
<!-- END: Navigation Menu primary_nav (Primary Navigation) -->
</div>
header.php – Location 1
<!-- BEGIN: Secondary Navigation Menu -->
<?php
if(function_exists('wp_nav_menu')) {
wp_nav_menu(
array(
'menu' => 'secondary_nav',
'container' => '',
'depth' => 1,
'menu_id' => 'secondary_nav_id'
)
);
}
else {
?>
<ul>
<?php wp_list_pages('title_li=&depth=1'); ?>
</ul>
<?php
}
?>
<!-- END: Secondary Navigation Menu -->
header.php – Location 2
In the admin page for the theme everything shows up just fine, both menus appear in the list both Primary Navigation and Secondary Navigation.
And from the admin screen I’ve added two distinct sets of menu items. However, whenever I load up my theme, for some reason I end up with only the menus from the Primary Navigation appearing twice.
Is there something I’ve forgotten that would cause this behavior?
Try
theme_location
instead ofmenu
in arguments. Too late here to look up specifics, but I remember documentation/code being absolutely confusing about that.In addition to Rarst’s and Chip’s answers above, register_nav_menu is used in this in manner:
register_nav_menu( $location, $description )
What you’ve specified as primary_nav and secondary_nav are actually menu location identifiers and not the actual menu identifiers.
That is why you have to use
theme_location
in your wp_nav_menu arguments instead ofmenu