Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I created some menus, and now I'm trying to set up a conditional construction with wp_nav_menu in header.php, but the behavior is not really as expected. I'm doing something like

<?php 
if ( is_front_page() )  
{
     wp_nav_menu( array( 'container_class' => 'menu-header', 'menu' => '68' ));
} 
elseif ( is_single() )  
{
     wp_nav_menu( array( 'container_class' => 'menu-header', 'menu' => '69' ) );
} 
else 
{
     wp_nav_menu( array( 'container_class' => 'menu-header', 'menu' => '33' ));
} 
?>

the last "else" catches 404s and pages, but with archives (categories, tags, search, author, ...) the menu falls back to the default fallback (wp_list_pages) instead of menu 33. Any ideas why this is happening? Note: I'm modifying the TwentyTen theme.

share|improve this question
    
Does menu 33 exist? (that ID is definately correct?) If so, does it have any items? ... also, any plugins installed? And if so, have you tried without them enabled? –  t31os Mar 20 '11 at 11:45
add comment

3 Answers

Ideally, you should be passing the "theme_location" argument to wp_nav_menu().

Register your three menus in functions.php:

register_nav_menus( array(
     'front_page' => 'Front Page Menu',
     'single' => 'Single Post Menu',
     'default' => 'Default Menu'
) );

Then, replace your code above with:

if ( is_front_page() )  
{
     wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'front_page' ));
} 
elseif ( is_single() )  
{
     wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'single' ) );
} 
else 
{
     wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'default' ));
} 

Then, ensure the appropriate custom menu is defined for each Theme Location, via Dashboard -> Appearance -> Menus

share|improve this answer
add comment

If you're using the menu parameter, you can also use the name or the slug. Please try those too. If you're sure about the ID, then you could also try using menu_id instead.

share|improve this answer
add comment

I discovered the problem was somehow caused by a pre_get_posts filter in my functions.php. In fact, I had an issue with this filter before, so I should've known ;) Cheers!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.