get_the_tag_list() WordPress Function

The get_the_tag_list() function is used to retrieve the list of tags for a given post. This function can be used within the WordPress Loop.

get_the_tag_list( string $before = '', string $sep = '', string $after = '', int $post_id ) #

Retrieves the tags for a post formatted as a string.


Parameters

$before

(string)(Optional) String to use before the tags.

Default value: ''

$sep

(string)(Optional) String to use between the tags.

Default value: ''

$after

(string)(Optional) String to use after the tags.

Default value: ''

$post_id

(int)(Optional) Post ID. Defaults to the current post ID.


Top ↑

Return

(string|false|WP_Error) A list of tags on success, false if there are no terms, WP_Error on failure.


Top ↑

More Information

This function 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.


Top ↑

Source

File: wp-includes/category-template.php

function get_the_tag_list( $before = '', $sep = '', $after = '', $post_id = 0 ) {
	$tag_list = get_the_term_list( $post_id, 'post_tag', $before, $sep, $after );

	/**
	 * 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 the tags.
	 * @param string $sep      String to use between the tags.
	 * @param string $after    String to use after the tags.
	 * @param int    $post_id  Post ID.
	 */
	return apply_filters( 'the_tags', $tag_list, $before, $sep, $after, $post_id );
}


Top ↑

Changelog

Changelog
VersionDescription
2.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.