How to Create Multiple Menu in WordPress?

Author : | Category : Wordpress | Last Updated :

If you are a WordPress developer you might have often come across situations where you need to create multiple menus for your WordPress site. Creating and managing multiple menus in WordPress is quite an easy task and can be done without fiddling with the codes. In this tutorial we shall take a look at the ways in which we can create multiple menus in WordPress. But before we go further into this discussion we need to understand how the menu management area works.

multiple-menus

As like most other sections of the WordPress dashboard here also you will see the drag and drop concept. What separates WordPress from other tools is the fact that here you can easily create multiple menus. That’s not all you can also work on a variety of menu types. To access all these functions you need to login to your to your WordPress admin account and go to the Appearances Section in your dashboard where you will find Menu Manager which will have a list of mini panels.

  • Theme Locations – This is a prearranged coded theme location for menus. Some themes have this by default while in other cases you need to create it.
  • Custom Links – If you are planning to add any new items to the menu items this is the place where you can do it. You can also make use of external resources if you wish to.
  • Posts – You are likely to have multiple posts in your site and here you will be able to add posts to your menu from a long list of selection.
  • Pages – Here you will find the list of all the pages in your site that can be added to your menu.
  • Categories – As like pages here you will see the list of categories that you can add to your menu.

Creating A New Menu

To create a new custom menu you will need to click on the + tab that appears on the top of the screen. Specify a name for the new menu and then click Create Menu button. In some cases you might see an error messages as “This theme does not support menus”. This is a common problem with older WordPress themes that were created prior to the launch of WordPress 3.0. To bypass this problem you will need to some a little bit of coding.

Open your theme’s function.php file and add the following code to the bottom of the theme before the ?> closing tag:

if (function_exists('add_theme_support')) {
add_theme_support('nav-menus');
}

This will solve your problem and let you add a new menu to your theme. Alternately you can also make use of the ‘Custom Menu’ widget. This will allow you to add new menus to the theme’s sidebar.

Create Multiple Menus

If your theme includes the support for more than one menu you can easily create multiple menus using the above steps. The only thing that you must take note choosing an existing menu that you want to associate your new menu. These menus can be termed as ‘Primary’ and ‘Secondary’ menus. The following lines of code will help you created multiple menus in WordPress.

//Register Navigations
add_action( 'init', 'my_custom_menus' );
function my_custom_menus() {
register_nav_menus(
array(
'primary-menu' => __( 'Primary Menu' ),
'secondary-menu' => __( 'Secondary Menu' )
)
);
}

While adding the above code you will also need to add the following code to your WordPress header.php and footer.php files. Here in the example below we are defining the CSS class for the nav bars.

<?php wp_nav_menu (array('theme_location' => 'primary-menu','menu_class' => 'nav'));?>
<?php wp_nav_menu (array('theme_location' => 'secondary-menu','menu_class' => 'nav'));?>

Managing Menus

Once you have created menu(s) in WordPress there are several options that are there in your disposal.

  • Delete Menu – As the name suggests you can delete the menus and all the items under it. Click on the button to delete a menu.
  • Automatically add new top-level Pages – This option can be used to automatically add pages to the menu as and when they are created.
  • Add Menu Items – This option allows you to add detailed items to the menus. We have already discussed about this earlier and you can add custom posts, categories, URLs etc. to the menus that you have just created.

One thought on “How to Create Multiple Menu in WordPress?

  1. This is one very useful information. I am not too familiar yet with WordPress, though I am trying to learn a lot.

Comments are closed.


Digitalocean Banner