WordPress at Your Fingertips

the_tags() WP 2.3.0

Retrieve the tags links for a post.

Must be used inside WordPress Loop.

Uses the_tags filter.

1 time — 0.005842 sec (very slow) | 50000 times — 5.53 sec (fast) | PHP 7.1.2, WP 4.7.3

No Hooks.

Return

null. Outputs HTML code to the screen.

Использование

<?php the_tags( $before, $separator, $after ); ?>
$before(string)
String to use before the tags.
Default: 'Tags:'
$sep(string)
String to use between the tags.
Default: ', '
$after(string)
String to use after the tags.
Default: ''

Examples

#1. Links to post tags

Let's display, separated by commas, links to the tags that the post has. The default text before the links will be "Tags:":

<p><?php the_tags(); ?></p>

Tags: WordPress, Computers, Blogging

#2. Change the initial text and the separator between the tags:

<?php the_tags( 'The post`s relations: ', ' > '); ?>

The post`s relations: WordPress > Computers > Blogging

#3. Let's display the tags in <ul> list:

<?php the_tags( '<ul><li>','</li><li>','</li></ul>'); ?>

Changelog

Since 2.3.0 Introduced.

Code of the_tags() WP 5.8.1

function the_tags( $before = null, $sep = ', ', $after = '' ) {
	if ( null === $before ) {
		$before = __( 'Tags: ' );
	}

	$the_tags = get_the_tag_list( $before, $sep, $after );

	if ( ! is_wp_error( $the_tags ) ) {
		echo $the_tags;
	}
}

WP Loop

For posts

Posts, Pages, ...

No comments
    Log In