It’s telling you to not hard code a menu name into your header. Rather, declare a theme location and then, in the header, display the menu the user has associated with that location. For example, see https://github.com/Automattic/_s/blob/master/header.php#L49
Hello Steve,
So, for me to understand you mean this line of code:
<nav id="site-navigation" class="main-navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', '_s' ); ?></button>
<?php
wp_nav_menu(
array(
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
)
);
?>
</nav><!-- #site-navigation -->
I got on my theme the following:
<div class="menu">
<?php wp_nav_menu( array('menu' => 'main-menu', 'container' => '', 'items_wrap' => '<ul class="mega-menu">%3$s</ul>' )); ?>
</div>
so to fix it should I place this code bellow?
<div class="menu">
<?php
wp_nav_menu(
array(
'theme_location' => 'menu-1',
'menu_id' => 'main-menu',
'container' => '',
'items_wrap' =>
'<ul class="mega-menu">%3$s</ul>' )); ?>
</div>
Is this correct or what would be the correct code?
Thanks!
-
This reply was modified 2 years, 8 months ago by codeman1234.
Sorry, would this be the correct?
<div class="menu">
<?php wp_nav_menu( array('theme_location' => 'primary','menu' => 'main-menu', 'items_wrap' => '<ul class="mega-menu">%3$s</ul>' )); ?>
</div>
The only problem with this code is that when user chooses on customizer menu location and puts primary menu the main menu it seems that menu shows twice, once on top and second on the side, how can I fix code so second menu on side does not show?
Thanks again!
You may have two locations assigned to the primary menu.
Hello,
Ok so you mean this part of the code, correct?
array('theme_location' => 'primary','menu' => 'main-menu',
So, which one I remove ‘primary’or ‘menu’ from code?
Thanks!
Look, the best thing to do is to read through the _s theme and see how the folks at Automattic do it.
If this is a theme you’re planning on submitting to wp.org, you might also check with the experts in the #themereview channel on slack (https://make.wordpress.org/slack)