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.

get_the_tag_list() 描述


 <?php $tag_list get_the_tag_list$before$sep$after ); ?> 

This function does not display anything - if you want to put it straight onto the page, you should use echo get_the_tag_list();. Alternatively, you can assign it to a variable for further use by using $foo = get_the_tag_list();.

The variables are all optional. You can use HTML inside each of the fields.

get_the_tag_list() 用法



(string) (可选) Leading text.

默认值: ' '


(string) (可选) String to separate tags.

默认值: ' '


(string) (可选) Trailing text.

默认值: ' '

get_the_tag_list() 参数


  • 添加于 版本: 2.3.0

get_the_tag_list() 历史


get_the_tag_list() 函数的代码位于 wp-includes/category-template.php.

/* ----------------------------------
 * wordpress之魂 ©
 * ---------------------------------- */
 * Retrieve the tags for a post formatted as a string.
 * @since 2.3.0
 * @param string $before Optional. Before tags.
 * @param string $sep Optional. Between tags.
 * @param string $after Optional. After tags.
 * @param int $id Optional. Post ID. Defaults to the current post.
 * @return string|false|WP_Error A list of tags on success, false if there are no terms, WP_Error on failure.
function get_the_tag_list( $before = '', $sep = '', $after = '', $id = 0 ) {

	 * Filter 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 );

get_the_tag_list() 源文件