Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert a second menu into a WordPress template?

Tags:

php

wordpress

So I'm trying to add a second menu to a WordPress template - the first I've got by writing the following:

<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>

Now, I've got two menus registered in the functions.php file, as follows:

register_nav_menu('header', 'Header Menu');
register_nav_menu('ad-menu1', 'Ad Menu One');

How do I access whatever menu is in the second nav menu registered? Or am I registering incorrectly? I've tried:

<?php wp_nav_menu( array( 'theme_location' => 'ad-menu1', 'container_class' => 'menu-ads' ) ); ?>

But that only gives me a list of every category, which is NOT what I want.

How do I merely grab the menu that is associated with Ad Menu One/ad-menu1?

like image 443
Steven Matthews Avatar asked May 17 '12 12:05

Steven Matthews


1 Answers

Standard way of adding a secondary menu to a theme is as follows.

Add the function to create a new menu opening file functions.php and registering it:

register_nav_menus( array(
    'primary' => __( 'Primary Menu', 'yourtheme'),
    'secondary' => __( 'Secondary Menu', 'yourtheme' ),
 ) );

This brought up a 2nd menu in the Theme Menu options.

Next, add the code to the desired place on your theme file. In this case, it would be added to the footer.

<nav>
    <?php
        wp_nav_menu( array('container_class' => 'menu-footer',
        'theme_location' => 'secondary') ); ?>
</nav>
like image 104
inigomedina Avatar answered Nov 15 '22 04:11

inigomedina