How to Add More Navigation Menus to Your WordPress Theme

This guidance will explain you how to add more navigation menus to your WordPress Theme. Sometimes you may need to add an extra navigation menu with important or frequently used links to increase the usability of your WordPress site.

To create a new menu you need to edit your theme files. Before making changes to any of your core files, it’s best to backup your entire site in case something goes wrong along the way.

To add a new menu location option in your admin dashboard under Appearance > Menus you need to ‘register a menu’. All it takes is adding a snippet of code to your ‘functions.php’ file located under /wp-content/themes/your_theme/ directory on the server.

Registering New Menu

Access your server using ftp client or FileManager provided by your host. Navigate to /wp-content/themes/your_theme/ directory on your server. Open the ‘functions.php’ file for editing.

Scroll to the bottom of the file. If you’d like to add only one menu, add the following code on a new line:

function register_my_menu() {
register_nav_menu('additional-menu',__( 'Additional Menu' ));
}
add_action( 'init', 'register_my_menu' );

In this example, ‘Additional Menu’ is the name that will appear in your admin dashboard’s menu page. The ‘additional-menu’ name is what WordPress will understand to execute your code properly.

If you would like to add multiple menus to your site, add this code on a new line instead:

function register_my_menus() {
register_nav_menus(
array(
 'additional-menu' => __( 'Additional Menu' ),
 'another-menu' => __( 'Another Menu' ),
 'extra-menu' => __( 'Extra Menu' )
 )
 );
}
add_action( 'init', 'register_my_menus' );

You can add as many new menus as you’d like with this method. The same rules will apply when naming them. Save the changes you made to the file.

Creating new Menu in WordPress Dashboard

Head over to Appearance > Menus in your dashboard. You’ll notice your new menus will be listed under Theme Locations in the Manage Location section.

Feel free to create a new menu or use an existing one. Once you have created a new menu, you can also manage the locations where they are displayed under the ‘Manage Locations’ tab.

Adding Menu Locations to Your Theme

This is where you need to decide where you’d like to place your menu. If you’d like your menu to appear at the top of your page, you’ll need to edit the ‘header.php’ file. You can also put it in your footer which means you would edit the ‘footer.php’ file. You can even display a menu on a page by editing its template file or to a sidebar, editing its ‘sidebar.php’ file.

You can place your new menu where ever you’d like. Here’s the minimum amount of code you need to add to any of these locations:

<?php wp_nav_menu( array( 'theme_location' => 'additional-menu' ) ); ?>

Where additional-menu is your new menu.

You probably want to style your menu with CSS so it goes beyond basic functionality and also looks great. To do this, you’ll need to create a class and add it to your theme with the following code:

<?wp_nav_menu( array( 'theme_location' => 'additional-menu', 'container_class' => 'new_menu_class' ) ); ?>

Again, replace additional-menu with the menu name you chose. We created ‘new_menu_class’class as an example, feel free to specify your own style class here. Do not forget to add style rules for the new created class in your style.CSS file which is located under /wp-content/themes/your_theme/ directory on the server.

This is it, your theme got an additional menu and now you are one step closer to the greatest site ever.