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 trialDavid Halsell
1,730 PointsWhy use $defaults = array(... instead of wp_nav_menu( array(... ?
What's the difference between the two menu functions below? Why use one instead of the other?
$defaults = array(
'theme_location' => 'primary'
);
wp_nav_menu( 'defaults' );
OR
wp_nav_menu( array( 'theme_location' => 'primary' ) );
2 Answers
Kevin Korte
28,149 PointsThe only difference is for us humans. If you had a few options you wanted to pass to a function, the top example makes more sense as it would be more readable to a human.
If you only had one or two options to pass in, I'd just use the bottom example.
Both execute the same way.
NOTE your top example has a semantic flaw. You would pass in the $defaults
variable, so it would be wp_nav_menu( $defaults );
David Halsell
1,730 PointsAh, figured that was the case. They seemed to me functionally identical. Thanks for catching the error!