register_nav_menu()WP 3.0.0

Registers one location (place) for the menu, to which a menu can then be attached in the admin panel.

Such a menu is convenient because it can be very flexibly edited in the admin panel, adding links to any sections and pages of the site, as well as any other links. The menu is displayed in the template using the function wp_nav_menu().

The function automatically registers support for navigation menus for the theme.

That is, using this function, there is no need to pre-register support for menus for the theme: add_theme_support('menus').

To register several locations for menus at once, use register_nav_menus().

The function is typically called during the action after_setup_theme.

No Hooks.

Returns

null. The function does not return anything, it simply registers the menu location.

Usage

<?php register_nav_menu( $location, $description ); ?>
$location(string) (required)
Identifier of the menu location, as a slug - a literal string.
$description(string) (required)
Description of the menu area that will be displayed in the admin panel.

Examples

1

#1 Menu registration example

Use this code in the themes functions.php file.

add_action( 'after_setup_theme', 'theme_register_nav_menu' );

function theme_register_nav_menu() {
	register_nav_menu( 'primary', __( 'Primary Menu', 'textdomain' ) );
}

Once the menu is registered, go to the admin and add items to it, then display it in the template using wp_nav_menu().

Changelog

Since 3.0.0 Introduced.

register_nav_menu() code WP 7.0

function register_nav_menu( $location, $description ) {
	register_nav_menus( array( $location => $description ) );
}