WordPress at Your Fingertips

has_tag() WP 2.6.0

Checks if the current post has any of the given tags. A conditional tag.

The given in $tag parameter tags are checked against the post's tags — against: term_ids, names, or slugs. If only integers are passed it will be checked against the post's tags IDs (term_ids).

If no tags are given, determines if the post has any tag.

Uses: has_term()
1 time — 0.001853 sec (very slow) | 50000 times — 96.58 sec (very slow)

No Hooks.


true|false. True if the current post has any of the given tags (or any tag, if no tag specified). False otherwise.


has_tag( $tag, $post );
The tag name/term_id/slug or array of them to check for.
Default: ''
Post to check instead of the current post.
Default: null


#1 Check if the current post has any tags

if( has_tag() )
	echo 'The current post has tags!';

#2 Check if the post has kino tag

if( has_tag( 'kino' ) )
	echo 'The current post has tag `kino`';

#3 Check if the post 56 has tags 49 and 89 (you can use their names or slugs instead of the ids)

if( has_tag( [45,89], 56 ) )
	echo 'Post 56 (ID) has tags ID 45 and 89';


Since 2.6.0 Introduced.
Since 2.7.0 Tags given as integers are only checked against the post's tags' term_ids, not names or slugs.
Since 2.7.0 Can be used outside of the WordPress Loop if $post is provided.

Code of has_tag() WP 5.8.1

function has_tag( $tag = '', $post = null ) {
	return has_term( $tag, 'post_tag', $post );

Conditional tags (all)

For posts

vladlu 100vlad.lu
Editors: Kama 101
No comments
    Log In