3
votes

I am trying to create multiple menu in WordPress. Actually menu created and I assigned them location and saved but the problem when I call footer menu and save its just show footer menu links in both header and footer section here is my Code please help me out where I am wrong thanks. I am using WordPress 4.1

Code: Header.php

<nav class="site-nav">
                <?php
                    $args = array(
                        'theme_location' => 'primary'
                    );
                ?>
                <?php wp_nav_menu( 'args' );?>
            </nav>

code: Footer.php

<nav class="site-nav">
    <?php
        $args = array(
            'theme_location' => 'footer'
        );
        ?>
        <?php wp_nav_menu( 'args' );?>
</nav>

code: functions.php

function register_my_menu() {
register_nav_menus( array(
    'header' => 'Header menu',
    'footer' => 'Footer menu') );
}
add_action( 'init', 'register_my_menu' );

Here is image:

First Header Menuenter image description here

Footer menu enter image description here

Locationenter image description here

resultenter image description here

Where I am Wrong

4

4 Answers

3
votes

In functions.php

// Register Navigation Menus
function register_my_menu() {
    $locations = array(
        'header' => 'Header Menu',
        'footer' => 'Footer Menu',
    );
    register_nav_menus( $locations );
}
add_action( 'init', 'register_my_menu' );

In header.php

wp_nav_menu( array( 'theme_location' => 'header') );

In footer.php

wp_nav_menu( array( 'theme_location' => 'footer') );

Make sure to check again via Menus > Manage Locations, and have at least one item on each menu.

0
votes

I'm not sure if this will be the solution or not. But try renaming the args to footer_args for the footer.

0
votes

It looks like your other menu is called header rather than primary. You probably just need to change the code in Header.php from

$args = array(
    'theme_location' => 'primary'
);

to

$args = array(
    'theme_location' => 'header'
);
0
votes

You can display menu without theme location by pass menu name in wp_nav_menu function.

for Header Menu,

wp_nav_menu( array('menu' => 'Header Menu' ));

for Footer Menu

 wp_nav_menu( array('menu' => 'Footer Menu' ));