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

Currently I have this code

$tag_list = get_the_tag_list('<ul><li>','</li><li>','</li></ul>');

and outputs:

    <li><a href="tag_link">tag_name</a></li>

How can I change it so it displays like this?

    <li><a href="tag_link"><span>tag_name</span></a></li>
share|improve this question
up vote 3 down vote accepted

So, from the get_the_tag_list() Codex entry:

  • $before
    • (string) (optional) Leading text.
    • Default: 'Tags: '
  • $sep
    • (string) (optional) String to separate tags.
    • Default: ', '
  • $after
    • (string) (optional) Trailing text.
    • Default: None

Since you're using this example:


...edited to save space...

Modify it as such:

get_the_tag_list( '<ul><li><span>', '</span></li><li><span>', '</span></li></ul>' );

...should get you what you're after.


I think you misunderstood my question. The span is supposed to be in the anchor tags. Your method would output <li><span><a></a></span></li>

Sorry about that; I misread the question.

This gets a bit trickier, but is entirely possible. The get_the_tag_list() template tag uses get_the_term_list(), which has a filter for the term links, called term_links-$taxonomy (which for tags would be, term_links-post_tag.

So, you could write a filter:

function mytheme_filter_post_tag_term_links( $term_links ) {
    $wrapped_term_links = array();
    foreach ( $term_links as $term_link ) {
        $wrapped_term_links[] = '<span>' . $term_link . '</span>';
    return $wrapped_term_links;
add_filter( 'term_links-post_tag', 'mytheme_filter_post_tag_term_links' );

Note: this will apply to every use of get_the_term_list() that outputs post tags. Caveat emptor.

share|improve this answer
hey there! I think you misunderstood my question. The span is supposed to be in the anchor tags. Your method would output <li><span><a></a></span></li> – hamahama Oct 27 '11 at 13:14
Okay, see updated answer; I indeed has misread your question. – Chip Bennett Oct 27 '11 at 13:50

you could use a filter function, added to functions.php of your theme:

add_filter('the_tags', 'wp32234_add_span_get_the_tag_list');

function wp32234_add_span_get_the_tag_list($list) {
    $list = str_replace('rel="tag">', 'rel="tag"><span>', $list);
    $list = str_replace('</a>', '</span></a>', $list);
    return $list;
share|improve this answer
thanks, this works only for tags right? – hamahama Oct 27 '11 at 17:36
as far as I can see, this works on the_tags() and get_the_tag_list(). – Michael Oct 27 '11 at 17:50
this would make a perfect answer too! – hamahama Oct 27 '11 at 19:23

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.