How To Add Custom Menus In WordPress

Looking to add custom menus in WordPress for your custom theme? All you may need is to register the menu in your WordPress theme’s functions.php file.

Registering custom menus in WordPress

To register the custom menus in your WordPress theme, you need to add a function to register this in your theme’s functions.php file.

  1. Navigate to Appearance > Editor > Theme Functions from your WordPress Dashboard;
  2. Add in the code below to register three different menus (you can change this accordingly);
  3. Click Update File to save the changes.
function custom_menus() {
 register_nav_menus(
  array(
   'primary' => 'Primary menu',
   'secondary' => 'Secondary menu',
   'tertiary' => 'Tertiary menu'
  )
 );
}

add_action( 'init', 'custom_menus' );

Using custom menus in the front-end

You can use the custom menus you create in your WordPress theme by using the following code below to display wherever you need the menus shown.

wp_nav_menu(
 array(
  'theme_location' => 'primary',
  'container' => false,
 )
);

Note, you can read the WordPress documentation on wp_nav_menu(); to find out more on which arguments you can pass through the function’s array to better tailor the front-end results.

Using custom menus in the back-end (WordPress Admin)

To use and adjust the registered menus you’ve created through your WordPress theme’s functions.php file, you can follow the steps below.

  1. Navigate to Appearance > Menus in your WordPress Dashboard;
  2. Create a new menu and give it any recognisable name;
  3. After creating the menu and dragging in the pages you require, tick the display location you’ve registered to show in that specific location;
  4. Click Save Menu to save the changes.