Support » Fixing WordPress » Menu message

  • codeman1234

    (@codeman1234)


    Hello,

    I am developing my first theme and when I use recommended plugin Theme Check on my theme as recommended before uploading theme, I am getting the following required error:
    A menu name is being used for a menu in header.php. By using menu name, the menu would be required to have the exact same name in the WordPress admin area. Use a theme_location instead.

    I really don’t understand what to do here to fix error, can someone please give me a hand?

    Thanks!

    • This topic was modified 2 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Steve Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Volunteer

    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

    Thread Starter codeman1234

    (@codeman1234)

    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!

    o3magazine

    (@o3magazine)

    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!

    Moderator Steve Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Volunteer

    You may have two locations assigned to the primary menu.

    o3magazine

    (@o3magazine)

    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!

    Moderator Steve Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Volunteer

    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)

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.