Abdus Sattar Bhuiyan
Abdus Sattar Bhuiyan

Reputation: 3074

menu created dynamically is not working

I am creating a wordpress menu as follows:

   <?php wp_nav_menu(
        array(
          'theme_location' =>'main_nav',
          'walker' => new Walker_Nav_Primary()
        )
        ); ?>

It generates the menu with exact structured way as I expect. i.e:

<ul id="menu-primary" class="menu">
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-target="#">Mega</a>
          <ul class="dropdown-menu">
            <li><a href="https://www.facebook.com/">sub 1</a></li>
            <li><a href="https://www.facebook.com/">sub2</a></li>
          </ul>
        </li>
  </ul>

But hover effect is stop working. When I replace wp_nav_menu() with the generated html it works again. I checked all the jquery code is set at footer.php and my menu is located at header.php and get_header() is called before get_footer(). So everything should be okay if static html is okay. Strange! which wrong is going on behind the scene.

Upvotes: 0

Views: 31

Answers (2)

Saikat
Saikat

Reputation: 151

I think, your menu has some issues with closing HTML tag. Better way to debug HTML issue is:

  1. hold the menu HTML into a variable.
  2. Print the variable inside htmlentities function.
  3. Now you can visually see what's wrong with your printed HTML.

Hope that would help you to solve the issue. Thanks

Upvotes: 1

ild flue
ild flue

Reputation: 1361

You may need to add this into the array:

'echo' => true,

Such as

   <?php wp_nav_menu(
        array(
          'theme_location' =>'main_nav',
          'walker'         => new Walker_Nav_Primary(),
          'echo'           => true
        )
        ); ?>

The official document is shown here,

Upvotes: 0

Related Questions