Support » Themes and Templates » How to add <span> into wp_list_categories() variable?

  • Resolved anthonybarro


    When using the wp_list_categories() variable (usage: it displays the categories in your blog.

    I have, however, in the mean time stripped the “title”, which by default is “Categories:”, so that it now displays the following HTML:

        <li><a href="">Category 1</a></li>
        <li><a href="">Category 2</a></li>
        <li><a href="">Category 2</a></li>

    What I need now, is to figure out how to add “<span>” into the mix, IN the tag, so it becomes:

        <li><a href=""><span>Category 1</span></a></li>
        <li><a href=""><span>Category 2</span></a></li>
        <li><a href=""><span>Category 2</span></a></li>

    I cannot for the life of me figure out how to do this. All help will be GREATLY appreciated!
    Thanks in advance.


Viewing 4 replies - 1 through 4 (of 4 total)
  • For anyone who has the same issue, I found a solution based on an other one:

      $categories = get_categories();
      foreach ($categories as $cat) {
      echo '<li><a href="'.get_option('home').'/'.get_option('category_base').'/'.$cat->category_nicename.'/"><span>'.$cat->cat_name.'</span></a></li>';

    Thanks, anthonybarro. I wish the team would make all of these WP template tag arguments so that they are the same across the board. For example, why this granularity is possible with the bookmarks tag, but not the links, or categories, I will never understand.

    Strangely, anthonybarro’s solution did not work on my system. get_option(‘home’) and the category base were not being embedded so all the links went nowhere.

    Since I couldn’t figure out why this happened (using 2.7.1 after all), I did some more googling and found :

    <ul id="nav">
    <li><a href="<?php echo get_option('home'); ?>/"><span>Home</span></a></li>
    <?php echo preg_replace('@\<li([^>]*)>\<a([^>]*)>(.*?)\<\/a>@i’, ‘<li$1><a$2><span>$3</span></a>’, wp_list_categories(’echo=0&amp;orderby=name&amp;exlude=181&amp;title_li=&amp;depth=1′)); ?>


    Kinda weird. I got mine running using anthonynarro’s solution. WP 2.8.6.

    Thanks guys! Life save 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to add <span> into wp_list_categories() variable?’ is closed to new replies.