Codex tools: Log in / create account
Contents |
Returns an array of objects, one object for each tag assigned to the post. This tag must be used within The Loop.
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 . ' ';
}
}
?>
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 . '" />';
}
}
?>
<?php
$tag = get_the_tags();
if ($tag) {
$tag = $tag[0]; echo $tag->name;
}
?>