wp_nav_menu to $string
-
I am developing a site which has the same menu inside the header and the footer. The menu gets built by Appearance → Menus and then called using wp_nav_menu.
However, since I just need the exact same html in both the header and footer I wanted to store the wp_nav_menu inside a variable and then echo it out. ( I thought this would make my site run faster ) So I took a template part: menu.php and put this code inside it:$primary_menu_defaults = array( 'theme_location' => 'primair', 'container' => false, 'menu_class' => false, 'echo' => 0 ); $primary_menu = wp_nav_menu( $primary_menu_defaults );
Then, in both menu.php and footer.php I just do this:
<?php echo $primary_menu; ?>
This works in the menu.php but not in the footer.php. So here’s my question, how can I get echo $primary_menu to actually echo inside the footer.php?
To be clear, the front end part that’s controlled by footer.php doesn’t do anything. No code gets echoed but no error is thrown either.
- The topic ‘wp_nav_menu to $string’ is closed to new replies.