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

Greg Schudel
Greg Schudel
4,090 Points

why keyword function only used at specific parts in functions file?

Why is the keyword function only used in front of certain functions and not all of them?

// why is the keyword `function` not put in front of this one? Is this cause this is an `action` 
 ?
add_theme_support('menus');


//it makes sense to put it here, i get that.
function register_theme_menus() {

    register_nav_menus(

        array(
            'primary-menu' => __('Primary Menu')
        )


    );

}

// why no function keyword here? Cause it's an action?
add_action('init', 'register_theme_menus');

1 Answer

David Evans
David Evans
10,490 Points

The 'keyword' function is when you are defining a function's functionality, not when you're calling a function.

The two spots where you ask about why there is no keyword in front is because the add_theme_support() and add_action() are already defined and are only being called there.

In the code you have there, you are calling the function add_theme_support(). Then you are defining a function called register_theme_menus(), and lastly you are calling the function add_action()