get_the_tag_list( string $before = '', string $sep = '', string $after = '', int $id )
Retrieve the tags for a post formatted as a string.
Description Description
Parameters Parameters
- $before
-
(string) (Optional) Before tags.
Default value: ''
- $sep
-
(string) (Optional) Between tags.
Default value: ''
- $after
-
(string) (Optional) After tags.
Default value: ''
- $id
-
(int) (Optional) Post ID. Defaults to the current post.
Return Return
(string|false|WP_Error) A list of tags on success, false if there are no terms, WP_Error on failure.
Source Source
File: wp-includes/category-template.php
function get_the_tag_list( $before = '', $sep = '', $after = '', $id = 0 ) {
/**
* Filters the tags list for a given post.
*
* @since 2.3.0
*
* @param string $tag_list List of tags.
* @param string $before String to use before tags.
* @param string $sep String to use between the tags.
* @param string $after String to use after tags.
* @param int $id Post ID.
*/
return apply_filters( 'the_tags', get_the_term_list( $id, 'post_tag', $before, $sep, $after ), $before, $sep, $after, $id );
}
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.
A Slightly More Complex Example
This checks if the post has any tags, and if there are, outputs them to an unordered list.
/** @var string|false|WP_Error $tag_list */ $tag_list = get_the_tag_list( '<ul><li>', '</li><li>', '</li></ul>' ); if ( $tag_list && ! is_wp_error( $tag_list ) ) { echo $tag_list; }This will return something in the form:
You can add classes and styles with CSS, as necessary.
A Basic Example
This outputs the list of tags inside a paragraph, with tags separated by commas.
This would return something like: