Example 1 — Tag page heading
Print the tag name in an h1.
<h1><?php single_tag_title(); ?></h1> How It Works
- The visitor is on the "PHP" tag archive.
- The function prints the tag name.
- It goes inside the
h1.

In WordPress, single_tag_title() shows the name of the current tag on a tag archive page, such as "WordPress" or "PHP".
It works on tag archives only. Use is_tag() when you want to check the page first.
Use it in tag.php or archive.php.
<?php
single_tag_title(); | Call | What it does |
|---|---|
single_tag_title() | Prints the tag name. |
single_tag_title( 'Tag: ' ) | Prints the name with a prefix. |
single_tag_title( '', false ) | Returns the name instead of printing. |
For categories use single_cat_title().
single_tag_title( string $prefix = '', bool $display = true ): string|void | Parameter | Description |
|---|---|
$prefix | string. Text to print before the name. Default is empty. |
$display | bool. true (default) prints the name. false returns it. |
| Return Value | Description |
|---|---|
| void | When $display is true, the name is printed. |
| string | When $display is false, the name is returned (without the prefix). |
Three short theme examples. Each one shows the code and what it prints.
Print the tag name in an h1.
<h1><?php single_tag_title(); ?></h1> h1.Print "Tag: PHP".
<h1><?php single_tag_title( 'Tag: ' ); ?></h1> Use the name in a sentence.
<?php
if ( is_tag() ) {
$tag = single_tag_title( '', false );
echo 'Posts tagged ' . esc_html( $tag );
} is_tag() checks for a tag archive.false returns the name.Print or return the name of the current term on a category, tag, or custom taxonomy archive.
9 people found this page helpful