E
E
Eugene Chefranov2018-05-13 18:03:19
CMS
Eugene Chefranov, 2018-05-13 18:03:19

How to properly display menu in WordPress?

The following menu structure is required

<nav>
                <ul class="header-menu">
                    <li><a href="#">Item 1</a></li>
                    <li><a href="#">Item 2</a></li>
                    <li><a href="#">Item 3</a></li>
                </ul>
            </nav>

I am trying to output with the following code
<?php 
        $args = array(
          'theme_location' => 'primary',
          'container' => 'nav',
          'container_class' => 'navigation',
          'menu_class' => 'header-menu',
          'depth' => 1
        );
      
        wp_nav_menu( $args );
            ?>

It seems that I wrote everything correctly, but the menu is displayed without a class on ul, and the class that should be on ul is transferred to nav.
<nav class="header-menu"><ul>
<li class="page_item page-item-2"><a href="#">Item 1</a></li>
<li class="page_item page-item-98"><a href="#">Item 2</a></li>
<li class="page_item page-item-96"><a href="#">Item 3</a></li>
</ul></nav>

How to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Syomka Gavrilenko, 2018-05-14
@Chefranov

$args = array(
  'theme_location' => 'primary',
  'container' => false,
  'items_wrap'      => '<nav><ul class="header-menu">%3$s</ul></nav>',
  'depth' => 1
);
wp_nav_menu( $args );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question