• There are span tags in my site’s menu, but I can’t figure out why. The only php generating span tags in my files is php I put in there.

    wp_nav_menu php

    <?php
      wp_nav_menu(
        array(
          'theme_location' => 'primary',
          'link_before' => '<span class="menu-link">',
          'link_after' => '</span>')
        )
    ?>

    Yet for some reason, the menu includes this additional tag with a mystery origin.

    Menu item html on the front end

    <li id="menu-item-350" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-350">
      <a href="[url]">
        <span class="menu-link">
          <i class="_mi _before fa fa-thumbs-o-up" style="vertical-align:text-top;"></i>
          <span>
            Testimonials
          </span>
        </span>
      </a>
    </li>

    Is there somewhere else I should be looking? Some keyword that I’m not searching? (I’ve already tried the obvious ones. Obvious to me anyway.)

Viewing 7 replies - 1 through 7 (of 7 total)
  • This is the appropriate page…

    https://codex.www.ads-software.com/Function_Reference/wp_nav_menu

    Worth having a good look through the docs.

    'container'       => 'div',
    'container_class' => '',
    'container_id'    => '',

    Do you need to specific a container perhaps?

    Thread Starter busboywithasilencer

    (@fakob)

    @colin

    re: your first post
    There doesn’t appear to be anything in the codex that answers my question. If I’m missing something, would you mind specifying where I should be looking please? It doesn’t appear to mention how span tags can inexplicably appear in menu items.

    re: your second post
    I’ve already added a specific span. It’s the “menu-link” that appears in the html. That I can account for. I just don’t understand where the other span, which has no associated class, nor php that can explain its presence in my menu items.

    What theme are you using? It could be something added by your theme (or a plugin), especially because there’s a FontAwesome icon added beforehand as well.

    Thread Starter busboywithasilencer

    (@fakob)

    @stephen

    I’m using Menu Icons. Searching for ‘span’ and ‘items_wrap’ in the repository yields nothing, unfortunately.

    It’s definitely coming from that plugin. If you check out lines 234 to 239 of includes/type-fonts.php, there’s this code:

    $class = ! empty( $values['hide_label'] ) ? 'visuallyhidden' : '';
    $title = sprintf(
      '<span%s>%s</span>',
      ( ! empty( $class ) ) ? sprintf( ' class="%s"', esc_attr( $class ) ) : '',
      $title
    );

    It looks like the code adds the class “visuallyhidden” to the <span> tag if you select the option to hide the link text. You could rewrite the code to only output the <span> tag if you’re going to hide the link text and submit a pull request.

    Thread Starter busboywithasilencer

    (@fakob)

    Great catch. Thank you very much.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘wp nav menu includes span tags that are not in wp_nav_menu.php’ is closed to new replies.