wp_create_nav_menu() WordPress Function

The wp_create_nav_menu() function allows you to create a custom navigation menu for your Wordpress site. This function takes two arguments: a name for your menu, and an optional array of menu items. To use this function, simply add the following code to your theme's functions.php file: wp_create_nav_menu( 'Main Menu', array( 'menu-item-1' => __( 'Home' ), 'menu-item-2' => __( 'About' ), 'menu-item-3' => __( 'Contact' ), ) );

wp_create_nav_menu( string $menu_name ) #

Creates a navigation menu.


Description

Note that $menu_name is expected to be pre-slashed.


Top ↑

Parameters

$menu_name

(string)(Required)Menu name.


Top ↑

Return

(int|WP_Error) Menu ID on success, WP_Error object on failure.


Top ↑

Source

File: wp-includes/nav-menu.php

function wp_create_nav_menu( $menu_name ) {
	// expected_slashed ($menu_name)
	return wp_update_nav_menu_object( 0, array( 'menu-name' => $menu_name ) );
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.