WordPress single_tag_title() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Archive title

Definition

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.

Syntax

Call it on a tag archive. Pass a prefix, or set display to false to get the name as a string.

WordPress
single_tag_title();
single_tag_title( 'Tag: ' );
$name = single_tag_title( '', false );
CallWhat 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.

Full declaration
WordPress
single_tag_title( string $prefix = '', bool $display = true ): string|void

Parameters

ParameterDescription
$prefixOptional. Text placed before the name when it is printed. Default is an empty string.
$displayOptional. true prints the name (default). false returns it.

Return Value

Return ValueDescription
stringThe tag name. Returned only when $display is false.
voidNothing is returned when the name is printed, or when the page is not a tag archive.

WordPress Examples

Three short theme examples. Each one has a sample output.

Example 1 — Print the title

Show the tag name in a heading.

WordPress
<h1><?php single_tag_title(); ?></h1>

How It Works

  1. On a tag archive the function prints the tag name.
  2. Put it inside your own h1 tag.
  3. No echo is needed because it prints by itself.

Example 2 — Add a prefix

Print a small label before the tag name.

WordPress
<h1><?php single_tag_title( 'Posts tagged: ' ); ?></h1>

How It Works

  1. The first argument is the prefix.
  2. WordPress prints the prefix and then the tag name.
  3. Include the space inside the prefix text.

Example 3 — Return the name

Get the name as a string and use it in a sentence.

WordPress
<?php
$name = single_tag_title( '', false );
echo '<p>You are reading posts tagged ' . esc_html( $name ) . '.</p>';
?>

How It Works

  1. false tells the function to return the name.
  2. The name is saved in $name.
  3. esc_html() keeps the output safe.

Frequently Asked Questions

It prints the name of the current tag on a tag archive page. With $display set to false, it returns the name.
No. It only works on tag archive pages. On a single post, use the_tags() or get_the_tags().
Pass false as the second argument: single_tag_title( '', false ).
No. The prefix is added only when the name is printed.
Use single_cat_title() for categories. Or use single_term_title(), which works for categories, tags, and custom taxonomies.

Next: single_term_title()

Print or return the title of a category, tag, or custom taxonomy archive.

single_term_title() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful