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 trialCulture Foundry
8,396 PointsWhen 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?
2 Answers
Culture Foundry
8,396 PointsIt 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?
eck
43,038 PointsGj 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
eck
43,038 PointsCan 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
8,396 PointsSorry 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);
?>
Culture Foundry
8,396 PointsCulture Foundry
8,396 PointsLooks like both menus end up with an id of #menu-footer-menu on the ul.