Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What's the best way to add an extra menu location to a theme that already has one?

I want to add an extra menu in a child theme of a theme that currently has a single custom menu (what is the correct terminology here?!).

Do I just use register_nav_menu() to create an additional menu?

share|improve this question
    
The answer is simple, and I believe you knew before asking. –  Jeremy Jared Nov 8 '11 at 11:49
    
@JeremyJared - pointless and incorrect accusation. The answer doesn't seem to be that simple as 2 people didn't get it right, which is why I spent some time working it out myself. You'll see my answer predates yours. –  anu Nov 8 '11 at 12:51
1  
@Jeremy Jared FYI there is nothing wrong with asking a question you know answer to. –  Rarst Nov 9 '11 at 9:53
add comment

3 Answers 3

up vote 2 down vote accepted

To answer my own question

Both register_nav_menu() and register_nav_menus() are additive, ie they add to the existing menu set (as long as you use a different location identifier). You don't need to redeclare an existing custom menu location that was created with either one of those calls.

share|improve this answer
add comment

there are two functions to register the menus: 1. register_nav_menu 2. register_nav_menus . The first registers only one menu location the other accepts arrays of menus. Thus, if you would like to add a new menu location you will need to use register_nav_menus();

    register_nav_menus( array(
                    'your_current_menu_location' => __( 'Your current menu label', 'your_theme' ),
                    'additional_location_' => __( 'Your additional menu label', 'your_theme'),

        //etc...
                ) );
share|improve this answer
    
I need to add ADDITIONAL menus - your answer does not make it clear if this works for this situation. –  anu Nov 7 '11 at 12:06
    
this code adds support for 3 menus, with three locations: top primary and footer. You can add as many as you like in the array. –  Daniel Sachs Nov 7 '11 at 13:39
    
Does your answer overwrite any existing locations that were already defined in the theme. –  anu Nov 7 '11 at 13:52
    
How is your menu registered now? by register_nav_menu();? –  Daniel Sachs Nov 7 '11 at 13:59
    
Any way, let's say that what you have now is <?php register_nav_menu( 'main', 'Main Menu' ); ?>. To add another one you need to use register_nav_menus(); (instead of the register_nav_menu) like this: register_nav_menus( array( 'main' => 'Main Menu', 'additional menu' => 'Additional Menu Label' ) ); Essentially you are declaring your old menu and the new menu in that array –  Daniel Sachs Nov 7 '11 at 14:05
show 1 more comment

You need to add this to the functions.php file for your theme, and remove the existing nav_menu function:

<?php
add_action( 'init', 'register_my_menus' );
function register_my_menus() {
register_nav_menus(
  array(
    // Add Your Current Menu Register Here And Replace The Current Code With This
    'secondary' => 'secondary' ,
    'tertiary' =>  'tertiary',
    )
  );
}
?>

To use the menu's you would place this in the template desired:

<?php wp_nav_menu( array( 'theme_location' => 'secondary' ) ); ?>

OR:

<?php wp_nav_menu( array( 'theme_location' => 'tertiary' ) ); ?>
share|improve this answer
    
The existing menu registration does not need to be removed - both register_nav_menu(s) functions are additive - ie they add to the set of menus that's already there. –  anu Nov 8 '11 at 11:25
    
OK, then follow the above instructions minus the part that says remove the existing function. You seem to think you know enough to correct everyone, but you can't figure out how to add an additional menu? –  Jeremy Jared Nov 8 '11 at 11:47
    
@Jeremy Jared let's keep things friendly, ok? I don't see why trivial comment with clarification is bringing out such seemingly aggressive response here. –  Rarst Nov 9 '11 at 10:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.