Andres Quintero
Andres Quintero

Reputation: 253

Adding a second navigation menu in wordpress

I need to add a second navigation menu below the main Nav Bar to the following wordpress site http://josema.dicosoftwareprojects.com/.

This menu will not be sticky, only the main one will remain sticky.

I tried adding the following code to functions.php

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

and then added the following code to header.php

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

I can see the menu displayed under Menu settings, but cannot get the second navbar to appear under the main one.

Please see this image of a sample of what I'm trying to accomplish from http://www.nogales.edu.co

I added a red label to the main menu and the secondary menu.

Upvotes: 0

Views: 1792

Answers (2)

Beatroot
Beatroot

Reputation: 476

You have to add this second menu yourself to the header.php, it doesn't magically appear where you want it.

this is the most basic way to output a menu (there are other commands for menu-retrieval):

$args = array(
    'menu' => $menuid,
);

wp_nav_menu($args);

It will output your menu with ID and Class attributes and as unordered list, so you can format it via CSS.

wp_nav_menu takes many more arguments, but for me that's actually usually enough, just format the output nicely. Alternatively you can use the menu-walker/function included in the theme, but that needs more inspection.

Of course, always do changes in a child-theme.

Upvotes: 1

WPZA
WPZA

Reputation: 931

You can register multiple menus under one register_nav_menu() function.

function register_my_menu() {
    register_nav_menus( array(
        'primary' => 'Primary menu',
        'secondary' => 'Secondary menu',
        'tertiary' => 'Tertiary menu'
        )
    );
}

Upvotes: 0

Related Questions