0

I created an menu by admin panel > Appearence > Menu. I have just one menu page in menu_lateral_1 .

Or the result is

<li id="menu-menu_lateral_1" class="menu"></li>
<li id="menu-item-212" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-212"><a href="my_website">my page</a></li>

With following code :

    $args = array(
        'menu' => 'menu_lateral_1',
        'container' => '',
        'items_wrap' => '<li id="%1$s" class="%2$s">%3$s</li>'
);
wp_nav_menu($args);

I don't understand where the first item comes ?!

1
  • Are you sure you gave the menu the position it has on the frontend? What happens is you add a custom link to an external website?
    – janw
    Apr 26, 2012 at 8:47

1 Answer 1

1

Take a look at the Codex documentation. The items_wrap attribute is for wrapping the list elements as a whole - not each individual menu item:

Whatever to wrap the items with an ul, and how to wrap them with

If you look at this line you'll see that it is using sprintf to replace three place-holders in the provided items_wrap. The first being an ID, the second a class, and lastly the items.

Try:

wp_nav_menu( array( 
    'menu' => 'menu_lateral_1', 
    'items_wrap' => '<ul id=\"%1$s\" class=\"%2$s\">%3$s</ul>' 
  ) ); ?>

This should give:

<ul id="menu-menu_lateral_1" class="menu">
    <li id="menu-item-212" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-212"><a href="my_website">my page</a></li>
</ul>

Note: You should use theme_location rather than menu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.