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

PHP How to Build a WordPress Theme WordPress Theme Functions Creating a Dynamic Menu

Need More details of passing values on variables.

This video does not describe how values are passing from function to function. example I don't understand how the below code works

$args=array('menu' =>'main-menu'); wp_nav_menu($args);

Q1. How this two line interconnected.? Q2. Why we need to write menu=main-menu? Can we write something else instead of menu or main-menu Q3. How values are passing from dashboard to wp_nav_menu function? or Functions.php file to header.php files. Q.4 Why we need to create menu in admin area how it passes to functions.php file

and so on...

1 Answer

Mike Baxter
Mike Baxter
4,442 Points

The Build a Simple PHP Application project will help you understand most of that, but you'd have to get through almost all of the project before you understand the concepts to answer all of your questions.

I don't know the answer to your Wordpress-specific questions, but as for your first question about the PHP:

$args means "arguments". wp_nav_menu means "WordPress Navigation Menu," and you're able to pass a series of arguments into the navigation menu.

The big concept here is what that "menu"=>"main-menu" is doing, and why you see that => in the code. What it's saying is there is some key-value pair: the key is "menu", and its associated value is "main-menu." You need that key-value pair concept because you might be passing in a bunch of different arguments. An argument is just a piece of information the function needs in order to act. In your example, it seems like all the function needs to know is which menu to displayβ€”but there might be other options you can tell the function about. According to the documentation, another argument you can pass is the "theme_location". I assume that means the http location, such as a Git repository.

I'm not sure what other Wordpress functions might be useful to you, but hopefully that's enough information to help you understand what's going on.

Cheers!