WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get the tag list

Description

Generates a HTML string of the tags associated with the current post. The name of each tag will be linked to the relevant 'tag' page. You can tell the function to put a string before and after all the tags, and in between each tag. Differently from get_the_category_list, this tag must be used inside The Loop.

Usage

 <?php $tag_list get_the_tag_list$before$sep$after ); ?> 

This function does not display anything - if you want to put it straight onto the page, you should use echo get_the_tag_list();. Alternatively, you can assign it to a variable for further use by using $foo = get_the_tag_list();.

The variables are all optional. You can use HTML inside each of the fields.

Parameters

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

Example

A Basic Example

This outputs the list of tags inside a paragraph, with tags separated by commas.

<?php
echo get_the_tag_list('<p>Tags: ',', ','</p>');
?>

This would return something like:

<p>Tags: 
<a href="tag1">Tag 1</a>,
<a href="tag2">Tag 2</a>,
...
</p>

A Slightly More Complex Example

This checks if the post has any tags, and if there are, outputs them to a standard unordered list.

<?php
if(get_the_tag_list()) {
    echo get_the_tag_list('<ul><li>','</li><li>','</li></ul>');
}
?>

This will return something in the form:

<ul>
<li><a href="tag1">Tag 1</a></li>
<li><a href="tag2">Tag 2</a></li>
 ... 
</ul>

You can add classes and styles with CSS, as necessary.

Change Log

Source File

get_the_tag_list() is located in wp-includes/category-template.php.

Related

Tags: get_tag(), get_tag_link(), get_tags(), get_the_tag_list(), get_the_tags(), is_tag(), the_tags(), single_tag_title(), tag_description(), wp_generate_tag_cloud(), wp_tag_cloud(), get_the_term_list()

See also index of Function Reference and index of Template Tags.