register_nav_menu()WP 3.0.0

Registers a navigation menu location for a theme.

No Hooks.

Return

null. Nothing (null).

Usage

register_nav_menu( $location, $description );
$location(string) (required)
Menu location identifier, like a slug.
$description(string) (required)
Menu location descriptive text.

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 6.5.3

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