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.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Try theme_location instead of menu in arguments. Too late here to look up specifics, but I remember documentation/code being absolutely confusing about that.

share|improve this answer
    
Yes, for whatever odd reason that did fix the problem...thanks! –  leeand00 Apr 13 '11 at 0:33
1  
Yep; you need to use the theme_location argument, which is what your arguments in register_nav_menu() define. What's happening is that wp_nav_menu() is looking for a menu that is named "primary_nav" and "secondary_nav". Since neither exists, both calls to wp_nav_menu() are falling back to the default, wp_page_menu() output. –  Chip Bennett Apr 13 '11 at 0:34
    
I was reading a book on it actually, it must be out of date. For anyone whose interested, here is the relevant documentation: codex.wordpress.org/Function_Reference/wp_nav_menu –  leeand00 Apr 13 '11 at 0:39
    
Might be helpful to name that book... –  t31os Apr 13 '11 at 9:58

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.