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.
Parameters
- $menu_name
(string)(Required)Menu name.
Return
(int|WP_Error) Menu ID on success, WP_Error object on failure.
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 ) ); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |