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

Juan Antonio Roig Bernat
Juan Antonio Roig Bernat
5,543 Points

Why "add_theme_support()" feature in functions.php instead of just a "function register_my_menus()"?

In the video:

The wp_nav_menu Function (https://teamtreehouse.com/library/wordpress-theme-development/building-out-wordpress-navigation/the-wpnavmenu-function)

Zack shows how to add a custom menu via functions.php placing the add_theme_support() with a register_themes_menus function. Like this:

add_theme_support ( 'menus' ); function register_theme_menus() { register_nav_menus() { array( 'primary-menu' => _( 'Primary Menu') ) ) }

But searching in codex, the example that they use is:

https://codex.wordpress.org/Navigation_Menus

function register_my_menus() { register_nav_menus( array( 'main-menu' => _( 'main-menu' ), 'extra-menu' => _( 'Extra Menu' ) ) ); } add_action( 'init', 'register_my_menus' );

It is because the wp version? Which is the best practise and why?

Thank you in advance.

Dan Barrett
Dan Barrett
10,450 Points

add_theme_support(); will allow for the default menu to show up if your building a custom theme. However if you want to register new menus on top of the default then you need a function to add those additional menus.