WordPress single_tag_title() Function

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

Definition

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.

Syntax

Use it in tag.php or archive.php.

WordPress
<?php
single_tag_title();
CallWhat 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().

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

Parameters

ParameterDescription
$prefixstring. Text to print before the name. Default is empty.
$displaybool. true (default) prints the name. false returns it.

Return Value

Return ValueDescription
voidWhen $display is true, the name is printed.
stringWhen $display is false, the name is returned (without the prefix).

WordPress Examples

Three short theme examples. Each one shows the code and what it prints.

Example 1 — Tag page heading

Print the tag name in an h1.

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

How It Works

  1. The visitor is on the "PHP" tag archive.
  2. The function prints the tag name.
  3. It goes inside the h1.

Example 2 — Add a prefix

Print "Tag: PHP".

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

How It Works

  1. The prefix is printed before the name.
  2. Include the space in the prefix.
  3. The heading now says what the page is.

Example 3 — Return the name

Use the name in a sentence.

WordPress
<?php
if ( is_tag() ) {
  $tag = single_tag_title( '', false );
  echo 'Posts tagged ' . esc_html( $tag );
}

How It Works

  1. is_tag() checks for a tag archive.
  2. false returns the name.
  3. We escape it and print the sentence.

Frequently Asked Questions

It prints or returns the name of the current tag on a tag archive page.
No. It only works on tag archives. Use get_the_tags() for the tags of a post.
Pass false as the second argument: single_tag_title( '', false ).
Use single_cat_title() for categories and single_term_title() for any term.

Next: single_term_title()

Print or return the name of the current term on 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