Title: register_nav_menus
Published: April 25, 2014
Last modified: February 24, 2026

---

# register_nav_menus( string[] $locations = array() )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#wp--skip-link--target)

Registers navigation menu locations for a theme.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#parameters)󠁿

 `$locations`string[]optional

Associative array of menu location identifiers (like a slug) and descriptive text.

Default:`array()`

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#more-information)󠁿

See [register_nav_menu()](https://developer.wordpress.org/reference/functions/register_nav_menu/)
for creating a single menu, and [Navigation Menus](https://codex.wordpress.org/Navigation_Menus)
for adding theme support.

This function automatically registers custom menu support for the theme, therefore
you do **not** need to call `add_theme_support( 'menus' );`

Use [wp_nav_menu()](https://developer.wordpress.org/reference/functions/wp_nav_menu/)
to display your custom menu.

On the **Menus** admin page, there is a **Show advanced menu properties** to allow_“
Link Target” “CSS Classes” “Link Relationship (XFN) Description”_

Use [ get_registered_nav_menus](https://developer.wordpress.org/reference/functions/get_registered_nav_menus/)
to get back a list of the menus that have been registered in a theme.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#source)󠁿

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

    	add_theme_support( 'menus' );

    	foreach ( $locations as $key => $value ) {
    		if ( is_int( $key ) ) {
    			_doing_it_wrong( __FUNCTION__, __( 'Nav menu locations must be strings.' ), '5.3.0' );
    			break;
    		}
    	}

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/nav-menu.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/nav-menu.php#L90)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/nav-menu.php#L90-L103)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#related)󠁿

| Uses | Description | 
| [add_theme_support()](https://developer.wordpress.org/reference/functions/add_theme_support/)`wp-includes/theme.php` |

Registers theme support for a given feature.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [_doing_it_wrong()](https://developer.wordpress.org/reference/functions/_doing_it_wrong/)`wp-includes/functions.php` |

Marks something as being incorrectly called.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#)

| Used by | Description | 
| [register_nav_menu()](https://developer.wordpress.org/reference/functions/register_nav_menu/)`wp-includes/nav-menu.php` |

Registers a navigation menu location for a theme.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 6 content](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#comment-content-2348)
 2.    [SeherKhan](https://profiles.wordpress.org/seherkhan/)  [  9 years ago  ](https://developer.wordpress.org/reference/functions/register_nav_menus/#comment-2348)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%23comment-2348)
     Vote results for this note: 11[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%23comment-2348)
 4.      ```php
         if ( ! function_exists( 'mytheme_register_nav_menu' ) ) {
     
         	function mytheme_register_nav_menu(){
         		register_nav_menus( array(
         	    	'primary_menu' => __( 'Primary Menu', 'text_domain' ),
         	    	'footer_menu'  => __( 'Footer Menu', 'text_domain' ),
         		) );
         	}
         	add_action( 'after_setup_theme', 'mytheme_register_nav_menu', 0 );
         }
         ```
     
 5.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%3Freplytocom%3D2348%23feedback-editor-2348)
 6.   [Skip to note 7 content](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#comment-content-5206)
 7.    [cebbi](https://profiles.wordpress.org/cebbi/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/register_nav_menus/#comment-5206)
 8.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%23comment-5206)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%23comment-5206)
 9.  Refactoring Menu Slugs:
 10. If you just rename the slug of a registered menu location, it will disappear from
     the frontend. This means you need to reassign the menu to the new location in 
     the dashboard.
 11. In order to edit the slug of a menu location while automatically keeping the previously
     assigned menu, customize and use the following snippet after renaming the slug
     in `register_nav_menu()`:
 12.     ```php
         function cebbi_update_menu_location() {
     
         	// Get assigned menus from theme mods
         	$nav_menu_locations = get_theme_mod('nav_menu_locations');
     
         	// Check if old-slug was previously assigned
         	if (isset($nav_menu_locations['old-slug'])) {
     
         		// Verify that new location does not yet exist or is empty to avoid overwriting manual changes
         		if (!isset($nav_menu_locations['new-slug']) || $nav_menu_locations['new-slug'] === 0) { 
     
         			// Copy assigned menu index to new location
         			$nav_menu_locations['new-slug'] = $nav_menu_locations['old-slug'];
     
         			// Optional: delete the menu assignment to the old location
         			unset($nav_menu_locations['old-slug']);
     
         			// Update theme mod
         			set_theme_mod('nav_menu_locations', $nav_menu_locations);
         		}
         	}
         }
         add_action('after_setup_theme', 'cebbi_update_menu_location');
         ```
     
 13. Also, don’t forget to update the slug where it’s used to display the menu (`wp_nav_menu()`,`
     has_nav_menu()`).
 14. You can use [get_registered_nav_menus()](https://developer.wordpress.org/reference/functions/get_registered_nav_menus/)
     to verify that the `old-slug` is not registered in your theme, before removing
     the assigned menu.
 15.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%3Freplytocom%3D5206%23feedback-editor-5206)
 16.  [Skip to note 8 content](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#comment-content-479)
 17.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/register_nav_menus/#comment-479)
 18. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%23comment-479)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%23comment-479)
 19. **Example**
 20.     ```php
         register_nav_menus( array(
         	'pluginbuddy_mobile' => 'PluginBuddy Mobile Navigation Menu',
         	'footer_menu' => 'My Custom Footer Menu',
         ) );
         ```
     
 21.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%3Freplytocom%3D479%23feedback-editor-479)
 22.  [Skip to note 9 content](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#comment-content-2065)
 23.   [Khoi Pro](https://profiles.wordpress.org/khoipro/)  [  9 years ago  ](https://developer.wordpress.org/reference/functions/register_nav_menus/#comment-2065)
 24. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%23comment-2065)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%23comment-2065)
 25. Creating menus from your Custom Taxonomies.
 26. For example: I have a custom taxonomy named ‘Country’ with a few countries in 
     list.
      Right now I want to assign each country has a private name and using it
     for condition displayed on frontend.
 27.     ```php
         $tax = 'country-category';
     
         $terms = get_terms( $tax, [
         'hide_empty' => false,
         ]);
     
         $args = array(
         'primary' => __( 'Primary Menu', 'khoipro' ),
         'secondary' => __( 'Secondary Menu', 'khoipro' )
         );
     
         // Loop through all terms to add term id as menu id and term name as menu name.
         foreach( $terms as $term) {
         $args = array_merge($args, array(
         'primary_'.$term->slug => 'Country Menu ('.$term->name.')'
         ));
         }
     
         register_nav_menus( $args );
         ```
     
 28. So my output codes should be displayed in Menus > Manage Locations:
 29. * Primary Menu (id: primary)
      * Secondary Menu (id: secondary) * Country Menu (
     Japan) (id: primary_japan) * Country Menu (Singapore) (id: primary_singapore) *
     Country menu (Vietnam) (id: primary_vietnam)
 30. Have a proof in a real practice with a newly created project.
 31.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%3Freplytocom%3D2065%23feedback-editor-2065)
 32.  [Skip to note 10 content](https://developer.wordpress.org/reference/functions/register_nav_menus/?output_format=md#comment-content-5763)
 33.   [Abdallah Youssef](https://profiles.wordpress.org/abdallahussef/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/register_nav_menus/#comment-5763)
 34. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%23comment-5763)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%23comment-5763)
 35.     ```php
         //function to add nav menu in Navigation Bar and Footer Bar:
     
         function add_nav_menus() {
             register_nav_menus( array(
                 'nav menu'=>'Navigation Bar',
                 'footer menu'=> 'Footer Bar',
             ));
         }
         add_action('init', 'add_nav_menus');
         ```
     
 36.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F%3Freplytocom%3D5763%23feedback-editor-5763)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_nav_menus%2F)
before being able to contribute a note or feedback.