Add <span> within the <li> output of <? wp_nav_menu() ?>

Im currently printing out:

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

Which outputs:

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

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

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

Any ideas on how to adjust this?

Related posts

1 comment

  1. Use the arguments before and after:

    wp_nav_menu(
        array(
            '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'
    

Comments are closed.