Jason
Jason

Reputation: 7682

Wordpress child theme, adding secondary menu

    <?php
    if ( function_exists('has_nav_menu') && has_nav_menu('primary-menu') ) {
        wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'main-nav', 'menu_class' => 'nav fl', 'theme_location' => 'primary-menu' ) );
    } else {
    ?>

I'm trying to add a secondary menu from Wordpress menu management in my functions.php of my child theme for Woothemes Canvas. I figure there's a way to add it to the array above but I can't get it to work. Thoughts?

Upvotes: 4

Views: 6351

Answers (2)

Nahid
Nahid

Reputation: 3045

But in my case, I did not use the init action, just put the menu register function in my child theme's function.php file

register_nav_menu( 'footer', 'Footer Menu' );

Upvotes: 0

RichardTape
RichardTape

Reputation: 21713

Jason, you first need to register your 'new' (secondary) menu with register_nav_menu() like:

add_action( 'init', 'register_my_menu' );

function register_my_menu() {
    register_nav_menu( 'secondary-menu', __( 'Secondary Menu' ) );
}

You do this in your theme's functions.php file.

Then you're able to call that menu in your template files. To use your code above, you'll probably want something like:

if ( function_exists('has_nav_menu') && has_nav_menu('secondary-menu') ) {
        wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'secondary-nav', 'menu_class' => 'nav fl', 'theme_location' => 'secondary-menu' ) );
    }

or maybe

if ( function_exists('has_nav_menu') && has_nav_menu('primary-menu') && has_nav_menu('secondary-menu') ) {
        wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'main-nav', 'menu_class' => 'nav fl', 'theme_location' => 'primary-menu' ) );

        wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'secondary-nav', 'menu_class' => 'nav fl', 'theme_location' => 'secondary-menu' ) );
    }

The second one will output both menus if they both exist, the first one will probably be used in addition to the one you posted in your initial question.

Upvotes: 6

Related Questions