Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress WordPress Theme Development Building Out WordPress Navigation The wp_nav_menu Function

Culture Foundry
Culture Foundry
8,396 Points

When I try to set up a second menu in the footer, both menus end up being the same.

Adding a second menu to the footer. I've added it to the functions.php:

<?php //this tells WP that our theme has specific menu areas
function register_theme_menus() {
  register_nav_menus(
    array(
    'primary-menu' => __( 'Primary Menu' ),
    'footer-menu' => __( 'Footer Menu' )
    )
  );
?>

And also to footer.php:

<?php //set wp_nav_menu defaults
  $defaults = array(
    'container' => false,
    'theme_loation' => 'footer-menu',
    'menu_class' => 'footer-menu',
    'depth' => 0
  );
  wp_nav_menu($defaults);
?>

And then setting up the footer menu in the WP Admin. What results is that both menus are the same, no matter what I put in the WP Admin. What am I not understanding about how menus are set up? Are there other steps that need to be taken to setup more then one menu?

Culture Foundry
Culture Foundry
8,396 Points

Looks like both menus end up with an id of #menu-footer-menu on the ul.

2 Answers

Culture Foundry
Culture Foundry
8,396 Points

It seems to work as expected when I forgo the $defaults variable. That is to say, if I put the array directly into the wp_nav_menu function for each menu, for example:

<?php
  wp_nav_menu( array( 'theme_location' => 'primary-menu', 'container' => false, 'menu_class' => 'main-menu' ) );
?>

Should I be using a unique var for each menu? Or is there some way to clear out the settings after WP has created each menu? Or maybe its something different altogether?

Gj getting it to work!

From everything I have been able to see, am not sure what was causing the problem though. Using the $defaults variable the way you described should have worked as you intended O.o

Can we also see the code that you used to include the menus in their respective locations? You might be echoing the same menu in both the footer and the header.

Culture Foundry
Culture Foundry
8,396 Points

Sorry about that, the other call is in the header.php:

        <?php //set wp_nav_menu defaults
          $defaults = array(
            'container' => false,
            'theme_loation' => 'primary-menu',
            'menu_class' => 'main-menu',
            'depth' => 0
          );
        wp_nav_menu($defaults);
        ?>