WordPress Nav Menus

Beginner
7 min read
Updated: Nov 2026
2 examples
Core concept

Definition

A nav menu is a list of links, like Home, About, and Contact. In WordPress you build it in the admin under Appearance > Menus, so you can add, remove, and reorder links without code.

Your theme decides where a menu shows. It does this with theme locations, for example primary for the header and footer for the footer. The theme prints the menu with wp_nav_menu().

Three steps.

1) Register a location in functions.php. 2) Assign a menu to it in Appearance > Menus. 3) Print it with wp_nav_menu().

Syntax

Register a location, then show it.

WordPress
<?php
// functions.php
register_nav_menus( array( 'primary' => 'Primary Menu' ) );

// header.php
wp_nav_menu( array( 'theme_location' => 'primary' ) );

Locations and Menus

A location is a place in the theme. A menu is the list of links you put there.

PartWhere you set itFunction
Theme locationfunctions.phpregister_nav_menus()
Menu and its linksAppearance > MenusAdmin screen
Show the menuTheme template, such as header.phpwp_nav_menu()

register_nav_menus() takes an array of slug => label. The label is what the admin sees. Use register_nav_menu() (singular) when you have only one location.

wp_nav_menu() vs walk_nav_menu_tree()

wp_nav_menu() is the everyday function. walk_nav_menu_tree() is a helper inside it.

wp_nav_menu()walk_nav_menu_tree()
JobShow a full menuBuild the list items from menu items
Who uses itAlmost every themeAdvanced custom output
Needs a walker?No (it uses Walker_Nav_Menu)Yes, passed in $args or the default one
Guidewp_nav_menu()walk_nav_menu_tree()
Custom walkers.

If you need special HTML, such as extra tags for a dropdown, write a class that extends Walker_Nav_Menu and pass it as the walker option of wp_nav_menu(). That is when walk_nav_menu_tree() matters.

WordPress Examples

Two short examples with sample output.

Example 1 — Show the primary menu

Register a location, then print its menu. The sample output shows fewer CSS classes than WordPress adds.

WordPress
<?php
            // functions.php
            function mytheme_menus() {
              register_nav_menus( array(
                'primary' => 'Primary Menu',
              ) );
            }
            add_action( 'after_setup_theme', 'mytheme_menus' );
            
            // header.php
            wp_nav_menu( array( 'theme_location' => 'primary' ) );

How It Works

  1. register_nav_menus() adds the primary location, and after_setup_theme is the right time to do it.
  2. In Appearance > Menus, assign a menu to Primary Menu.
  3. wp_nav_menu() prints the menu where you call it.

Example 2 — Use a nav tag and no fallback

Wrap the list in <nav> and show nothing if no menu is assigned.

WordPress
<?php
            wp_nav_menu( array(
              'theme_location' => 'primary',
              'container'      => 'nav',
              'menu_class'     => 'nav-list',
              'fallback_cb'    => false,
            ) );

How It Works

  1. container set to nav uses a <nav> tag instead of a <div>.
  2. menu_class sets the CSS class of the list.
  3. fallback_cb set to false prints nothing if no menu is assigned.

Next: WordPress Nav Menu Functions

Now that you know the basics, open the functions index for both guides.

Full list: WordPress Nav Menu Functions index (/wordpress/nav-menu/function).

Frequently Asked Questions

It is a list of links, such as Home, About, and Contact, that you build in Appearance > Menus and show in your theme.
It is a named spot in your theme, such as primary or footer. You register it with register_nav_menus() and assign a menu to it in the admin.
wp_nav_menu(). Pass theme_location to show the menu assigned to that location.
No menu is assigned to the location. Assign one in Appearance > Menus, or set fallback_cb to false to show nothing.
Not for normal themes. wp_nav_menu() calls it for you. It matters when you write a custom walker or build custom menu HTML.
Open the WordPress Nav Menu Functions index. It lists both guides in short tables.

Browse every nav menu function

Open the functions index for simple guides with examples and FAQs.

Nav Menu Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful