简体   繁体   中英

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'),
));

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM