Codex

Template Tags/get the tags

Contents

Description

Returns an array of objects, one object for each tag assigned to the post. This tag must be used within The Loop.

Usage

This function does not display anything; you should access the objects and then echo or otherwise use the desired member variables.

The following example displays the tag name of each tag assigned to the post (this is like using the_tags(), but without linking each tag to the tag view, and using spaces instead of commas):

<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ' '; 
}
}
?>

Examples

Show tag Images

This outputs tag images named after the term_id with the alt attribute set to name. You can also use any of the other member variables instead.

<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo '<img src="http://example.com/images/' . $tag->term_id . '.jpg" 
alt="' . $tag->name . '" />'; 
}
}
?>

Show the First tag Name Only

<?php
$tag = get_the_tags(); 
if ($tag) {
$tag = $tag[0]; echo $tag->name;
}
?>

Member Variables

term_id 
the tag id
name 
the tag name
slug 
a slug generated from the tag name
term_group 
the group of the tag, if any
taxonomy 
should always be 'post_tag' for this case
description 
the tag description
count 
number of uses of this tag, total

Related

Template:Tag tag Tags

How to pass parameters to tags with query-string-style parameters

Go to Template Tag index