Jack Averill
Jack Averill

Reputation: 841

I can't get both my header and footer menus to display properly in my wordpress theme

I've been trying to make a header menu for my main hyperlinks and a footer menu for my social media icons.

I've had the header one for a while, but it's only since I've tried to add a menu in the footer that it's started displaying only the footer menu in the header and footer. I've ensured that all of the settings are correct in the wordpress back end, but I still can't get this to work.

In my header.php I have:

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

In my footer.php I have:

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

And in the functions.php I have:

register_nav_menus(array( 
'header' => __( 'Header Menu'), 
'footer' => __( 'Footer Menu'),
));

Upvotes: 1

Views: 2356

Answers (1)

JBC
JBC

Reputation: 177

Please change into functions.php :

function register_my_menus() {
    register_nav_menus(
        array(
            'primary' => esc_html__( 'Primary Menu', 'theme_wp' ),    
            'header' => __( 'Menu Header' ),
            'footer' => __( 'Menu Footer' )
            /*'an-extra-menu' => __( 'An Extra Menu' ) */
        )
    );
}
add_action( 'init', 'register_my_menus' );

Now into template :

header.php

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

footer.php

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

Don´t forget asign menu into Options Wp --> https://codex.wordpress.org/Appearance_Menus_SubPanel

Upvotes: 1

Related Questions