the_tags()
Retrieve the tags links for a post.
Must be used inside WordPress Loop.
To change the output of this function, use the following hooks:
Uses: get_the_tag_list()
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>
#2 Change the initial text and the separator between the tags:
<?php the_tags( 'The post`s relations: ', ' > '); ?>
#3 Let's display the tags in <ul> list:
<?php the_tags( '<ul><li>','</li><li>','</li></ul>'); ?>
Changelog
Since 2.3.0 | Introduced. |
the_tags() the tags code WP 6.7.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; } }