Multiple WordPress Menus

July 14th, 2011
By: Cory Mathews

WordPress 3+ allows for custom theme controlled menus. For this example I will be adding 3 but the same works for 2, 3 or any number of wordpress menus.

In the functions.php file of the theme we first need to add support for menus.

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

The function_exists is only there for backward compatability.. so you can probably safely remove it. Without the add_theme_support when someone clicks on Appearance -> Menus they will get the message

“The current theme does not natively support menus, but you can use the “Custom Menu” widget to add any menus you create here to the theme’s sidebar.”

Next we need to define our menus using the register_nav_menu  function. The following defines 3 different menus; main, top and side to be used within our skin

if ( function_exists( 'register_nav_menu' ) ) {
  register_nav_menus( array(
    'main' => 'Main Navigation',
    'top' => 'Smaller top nav',
    'side' => 'nav within sidebar'
  ))
}

Now if we go to the menus page within WordPress we should see that our skin supports 3 different menus. With the descriptions we provided in the functions.php file.

Now we need to add these menu place holders to our theme so the menus appear in the appropriate places. So within your themes .php pages add the following line

<?php wp_nav_menu( array( 'theme_location' > 'top', 'container' > '' ) ); ?>

*The container parameter removes the (pointless) wrapping div tag.

Then for each of the other menus you add the above code again giving it the other menu items.