Example 1 — Print the title
Show the tag name in a heading.
<h1><?php single_tag_title(); ?></h1> How It Works
- On a tag archive the function prints the tag name.
- Put it inside your own
h1tag. - No
echois needed because it prints by itself.

In WordPress, single_tag_title() gives you the name of the tag on a tag archive page. Use it for the page heading.
By default it prints the name. Set $display to false to return the name instead. It only works on tag archive pages.
Call it on a tag archive. Pass a prefix, or set display to false to get the name as a string.
single_tag_title();
single_tag_title( 'Tag: ' );
$name = single_tag_title( '', false ); | Call | What it does |
|---|---|
single_tag_title() | Prints the tag name. |
single_tag_title( 'Tag: ' ) | Prints the prefix, then the name. |
single_tag_title( '', false ) | Returns the name as a string. Nothing is printed. |
Use it in tag.php or archive.php. It does nothing on other pages.
single_tag_title( string $prefix = '', bool $display = true ): string|void | Parameter | Description |
|---|---|
$prefix | Optional. Text placed before the name when it is printed. Default is an empty string. |
$display | Optional. true prints the name (default). false returns it. |
| Return Value | Description |
|---|---|
| string | The tag name. Returned only when $display is false. |
| void | Nothing is returned when the name is printed, or when the page is not a tag archive. |
Three short theme examples. Each one has a sample output.
Show the tag name in a heading.
<h1><?php single_tag_title(); ?></h1> h1 tag.echo is needed because it prints by itself.Print a small label before the tag name.
<h1><?php single_tag_title( 'Posts tagged: ' ); ?></h1> Get the name as a string and use it in a sentence.
<?php
$name = single_tag_title( '', false );
echo '<p>You are reading posts tagged ' . esc_html( $name ) . '.</p>';
?> false tells the function to return the name.$name.esc_html() keeps the output safe.Print or return the title of a category, tag, or custom taxonomy archive.
9 people found this page helpful