WordPress at a glance

register_nav_menus() WP 3.0.0

Registers multiple custom navigation menus locations for a theme, to which the menus are then attached.

Menus are setup in the settings of the theme (Menus section), and printed with wp_nav_menu().

When setting up a menu, you can add different links there: on categories, tags, pages, posts, external links, etc.


The function also adds menu support to the theme.

The function is usually called on after_setup_theme

Is the basis for: register_nav_menu()

No Hooks.


Nothing (null).


register_nav_menus( $locations );
Associative array of menu location identifiers (like a slug) and descriptive text.
Default: array()


#1 An example of registering multiple menus

It also automatically adds menu support to the theme.

add_action('after_setup_theme', function(){
	register_nav_menus( array(
		'header_menu' => 'Header menu',
		'footer_menu' => 'Footer menu'
	) );

We will display these menus with wp_nav_menu().


This function automatically adds menu support to the theme, so there's no need to call add_theme_support('menus') if you are using it.

In the menu settings of the theme, you can enable "Advanced Settings" that allow you to specify various attributes of the HTML links of the menu items.

Code of register nav menus: wp-includes/nav-menu.php WP 5.2

function register_nav_menus( $locations = array() ) {
	global $_wp_registered_nav_menus;

	add_theme_support( 'menus' );

	$_wp_registered_nav_menus = array_merge( (array) $_wp_registered_nav_menus, $locations );

Related Functions

From tag: nav menu (nav_menu)

More from category: Other Theme Functions

No comments
    Hello, !     Log In . Register