• Hi guys.
    i’ve got a problem menu after hooking to wordpress.
    I customized my menu by this code in header

    <header>
            <div class="container">
              <div class="brand">
                <a href="http://hesamstudio.com"><h2>Hesam<span>Studio</span></h2></a>
              </div>
        
              <div class="mobile-nav">
                <a href="#" class="open-menu">MENU</a>
              </div>
              <nav class="navbar">
                  <ul class="menu">
                  <li class="menu-item">
                    <a href="https://www.hesamstudio.com">Home</a>
                  </li>
                  <li class="menu-item">
                    <a href="<?php echo get_template_directory_uri(); ?>/about.html">About</a>
                  </li>
                  
                  <li class="menu-item">
                    <a href="#">Contact</a>
                  </li>
                  
                  <li class="menu-item has-sub-menu">
                    <a href="#">Portfolio</a>
        
                    <ul class="sub-menu">
                      <li class="menu-item">
                        <a href="<?php echo get_template_directory_uri(); ?>/illustration.html">Illustration</a>
                      </li>
                      
                      
                      <li class="menu-item">
                        <a href="<?php echo get_template_directory_uri(); ?>/bookillustration.html">Book Illustration</a>
                        
                      </li>
        
                      <li class="menu-item">
                        <a href="#">Portrait Design</a>
                      </li>
                      <li class="menu-item">
                        <a href="#">Sketches</a>
                        
                      </li>
                    </ul>
                  </li>
                  
                </ul>
                
                <a href="#" class="close-menu">Close Menu</a>
              </nav>
              
            </div>
          </header>

    after hooking by this code in function.php

    <?php
        function theme_setup(){
            add_theme_support('title-tag');
            register_nav_menus(array(
                'Main_Menu'=>'menu',
            ));
        }
        add_action("after_setup_theme","theme_setup");
    ?>

    and changing header code to below my menu theme doesn’t work properly and in wordpress after adding sample menu it doesn’t show home and other menu which has been added.

    <header>
            <div class="container">
              <div class="brand">
                <a href="http://hesamstudio.com"><h2>Hesam<span>Studio</span></h2></a>
              </div>
        
              <div class="mobile-nav">
                <a href="#" class="open-menu">MENU</a>
              </div>
              <nav class="navbar">
                 <?php wp_nav_menu(array(
                         'theme_location' => 'Main_Menu',
                         'depth' => '3',
                      )); ?>
                
                <a href="#" class="close-menu">Close Menu</a>
              </nav>
              
            </div>
          </header>
    • This topic was modified 4 years, 2 months ago by hesamfisher.
    • This topic was modified 4 years, 2 months ago by hesamfisher.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I tested the WP specific part of your code and it works fine on my test site. Be sure you’ve selected your menu under “Manage locations” tab. It’s possible to add a menu in the back end but never assign it to a location.

    Or your issue could simply be caching. Try flushing all caches involved, both client and server side before deciding there’s a problem with your code.

    It doesn’t seem to matter in this case, but by convention FWIW, internal tags or handles used by WP PHP code ('Main_Menu' in your case) should follow slug naming rules — all lower case and only - non-alpha-numeric character. While 'Main_Menu' does work, it’d be better as 'main-menu'. By consistently doing so, you avoid strange bugs in situations where it really does matter. The user visible label 'menu' can be any string you care to use.

Viewing 1 replies (of 1 total)

The topic ‘Problem in menu after hooking’ is closed to new replies.