get_the_tags( int $id )
Retrieve the tags for a post.
Description Description
Parameters Parameters
- $id
-
(int) (Required) Post ID.
Return Return
(array|false|WP_Error) Array of tag objects on success, false on failure.
Source Source
File: wp-includes/category-template.php
function get_the_tags( $id = 0 ) { /** * Filters the array of tags for the given post. * * @since 2.3.0 * * @see get_the_terms() * * @param WP_Term[] $terms An array of tags for the given post. */ return apply_filters( 'get_the_tags', get_the_terms( $id, 'post_tag' ) ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.3.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Print only the first tag name:
This example prints the tags of current post:
Code must be used in The Loop.
// Show post tags with link and a custom separator
Example using post ID to get tags:
This doesn’t need to be in The Loop.
Expand full source codeCollapse full source code
Execute code based on different tag values:
This code displays different HTML for different tags. Add
elseif
statements as needed.Expand full source codeCollapse full source code
Function to show tags in a dropdown:
Expand full source codeCollapse full source code
Loop with tag post by ID and Link to -> /tag/slug:
Expand full source codeCollapse full source code
Display tags with links to tag pages in an unordered list: