WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 0 down vote accepted

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'
share|improve this answer
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>? – user1231561 May 3 '13 at 22:17
@user1231561 I tested it, see my update. Make sure, your have actually set a menu for that theme location. – toscho May 3 '13 at 22:21
More info at codex.wordpress.org/Function_Reference/wp_nav_menu – shea May 3 '13 at 22:22
Thanks a lot guys - I got it working now! :) – user1231561 May 3 '13 at 23:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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