wp_nav_menu only works in header.php

0

I have 2 menus in the Wordpress website that I'm developing (top and bottom). The problem is that the wp_nav_menu function is only working correctly when placed in header.php. I'm 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 displaying it in the header like this:

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

and in the footer like this:

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

Yes, I have already linked the menus in the wordpress panel. The header works normally, footer prints a div with a class that I can not even understand where it comes from.

If I cut the menu code of footer.php and paste it into header.php it works! Could anyone tell me why this is happening and how to solve it?

    
asked by anonymous 18.05.2018 / 17:51

1 answer

0

Okay ... I've figured out the problem, I'll answer if anyone ever gets through this. The site I am developing searches the posts in a wortis multisite network, and for that I use the switch_to_blog ($ id_destino) to go home to search for posts. The problem was happening because I had forgotten to go back to the original site using switch_to_blog ($ id_site_original) ... that is, it was looking for the menu on any other site in the multisites network.

    
18.05.2018 / 21:33