Im currently printing out:

<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>

Which outputs:

<div class="menu">
<li class="current_page_item">Frontpage</li>
<li class="page_item page-item-2">etc</li>

In my original HTML setup ive got an <span> within the <li> which looks like this:

<div id="menu">
        <a href="#">Menu1</a>

Any ideas on how to adjust this?

1 Answer 1


Use the arguments before and after:

        'theme_location' => 'primary',
        'menu_class' => 'nav-menu',
        'before' => '<span>',
        'after' => '</span>'

To see how these arguments are used, look at the method start_el() in Walker_Nav_Menu:

    $item_output = $args->before; // 'before'
    $item_output .= '<a'. $attributes .'>';
    $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
    $item_output .= '</a>';
    $item_output .= $args->after; //'after'
  • Hi Toscho, thanks a lot for your response. I tried what you suggested, but am not seeing any <span> in the output. Would the thought be that the "before" + "after" will automatically set the <span> within the <li>? Commented May 3, 2013 at 22:17
  • @user1231561 I tested it, see my update. Make sure, your have actually set a menu for that theme location.
    – fuxia
    Commented May 3, 2013 at 22:21
  • More info at codex.wordpress.org/Function_Reference/wp_nav_menu
    – shea
    Commented May 3, 2013 at 22:22

Your Answer

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

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