is_tag()
Check if the tag archive page is displayed. Conditional tag.
This tag should be used before is_archive() in the logical chain of checks, because the tag page is considered one of the archive pages, just like categories, dates.
Uses: WP_Query::is_tag()
No Hooks.
Returns
true|false.
Usage
if( is_tag() ){
// code
}
- $tag (int/string/array)
- ID of the tag, name of the tag, slug of the tag, or an array of any of these values. An alternative name (slug) must be specified. The ability to specify tags in an array was added in version 2.5.
Default: ''
Examples
#1 Usage Examples
is_tag(); // When any tag archive page is displayed. is_tag( '30' ); // When the archive page is displayed tags with ID 30. is_tag( 'metka' ); // When the archive page is displayed tags with the 'metka' slug. is_tag( 'Tag' ); // When the tag page with the name 'Tag' is displayed. is_tag( [ 30, 'metka', 'Tag' ] ); // returns true when page with posts from tag with: // ID 30, or slug "metka", or tag name "Tag" is displayed.
Notes
- Global. WP_Query. $wp_query WordPress Query object.
Changelog
| Since 2.3.0 | Introduced. |
is_tag() is tag code WP 6.9
function is_tag( $tag = '' ) {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return false;
}
return $wp_query->is_tag( $tag );
}