wp_nav_menu only works in header.php

Asked

Viewed 28 times

0

I have 2 menus on the Wordpress site that I am developing (top and footer). The problem is that the wp_nav_menu function is only working correctly when placed in header.php. I am registering the menus as follows:

function register_my_menus() {
    register_nav_menus(
        array(    
            'header' => __( 'Menu Header' ),
            'footer' => __( 'Menu Footer' ),
        )
    );
}
add_action( 'init', 'register_my_menus' );

and I’m showing off in the header like this:

wp_nav_menu( array( 'theme_location' => 'header','items_wrap'      => '<ul class="menu-dinamico">%3$s</ul>' ) );

and on the footer like this:

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

Yes, I’ve linked the menus in the wordpress panel. The header works normal, the footer prints a div with a class I’m not even understanding where it comes from. inserir a descrição da imagem aqui

If I cut the code from the footer.php menu and paste it into header.php it works! Would anyone know why this is happening and how to solve it?

1 answer

0

OK...I discovered the problem, I will answer in case someone ever goes through it. The site I’m developing searches the posts on a network worpress Multisite, and for that I use the switch_to_blog ($id_destination) to go home site search for posts. The problem was happening because I had forgotten to return to the original site using switch_to_blog($id_site_original)...ie, he was looking for the menu on any other site in the network multisites.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.