The is_tag() WordPress PHP function determines whether the query is for an existing tag archive page. If a specific tag is provided, it checks if the query is for that particular tag.
Usage
is_tag($tag);
Parameters
$tag
(int|string|array) (Optional) – Tag ID, name, slug, or array of such to check against. Default: ”
More information
See WordPress Developer Resources: is_tag()
Introduced in WordPress version 2.3.0.
Examples
Check if any tag archive page is being displayed
This code checks if any tag archive page is being displayed.
if (is_tag()) { // Your code here }
Check if a specific tag by ID is being displayed
This code checks if the archive page for tag with ID 30 is being displayed.
if (is_tag(30)) { // Your code here }
Check if a specific tag by slug is being displayed
This code checks if the archive page for tag with the slug ‘extreme’ is being displayed.
if (is_tag('extreme')) { // Your code here }
Check if a specific tag by name is being displayed
This code checks if the archive page for tag with the name ‘mild’ is being displayed.
if (is_tag('mild')) { // Your code here }
Check if any of the specified tags are being displayed
This code checks if the tag of posts being displayed is either term_ID 30, or slug ‘extreme’, or name ‘mild’. The array ability was added at Version 3.7.
if (is_tag(array(30, 'mild', 'extreme'))) { // Your code here }