WordPress single_term_title() Function

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

Definition

In WordPress, single_term_title() gives you the name of the term on a term archive page. It works for categories, tags, and custom taxonomies.

By default it prints the name. Set $display to false to return the name instead. Use it when one template serves many taxonomies.

Syntax

Call it on any category, tag, or taxonomy archive. Pass a prefix, or set display to false.

WordPress
single_term_title();
single_term_title( 'Archive: ' );
$name = single_term_title( '', false );
CallWhat it does
single_term_title()Prints the name of the current term.
single_term_title( 'Archive: ' )Prints the prefix, then the name.
single_term_title( '', false )Returns the name as a string. Nothing is printed.

Use it in archive.php or taxonomy.php. It does nothing on other pages.

Full declaration
WordPress
single_term_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 term name. Returned only when $display is false.
voidNothing is returned when the name is printed, or when the page is not a term archive.

WordPress Examples

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

Example 1 — Print the title

Show the term name in a heading on any term archive.

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

How It Works

  1. On a term archive the function prints the term name.
  2. The same code works for categories, tags, and custom taxonomies.
  3. No echo is needed because it prints by itself.

Example 2 — Add a prefix

Print a label before the term name.

WordPress
<h1><?php single_term_title( 'Archive: ' ); ?></h1>

How It Works

  1. The first argument is the prefix.
  2. WordPress prints the prefix and then the term 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 page title.

WordPress
<?php
$name = single_term_title( '', false );
if ( $name ) {
  echo '<h1>Posts about ' . esc_html( $name ) . '</h1>';
}
?>

How It Works

  1. false tells the function to return the name.
  2. if ( $name ) checks that this is a term archive.
  3. esc_html() keeps the output safe.

Frequently Asked Questions

It prints the name of the current category, tag, or custom taxonomy term on an archive page. With $display set to false, it returns the name.
Use it when one template, such as archive.php, shows many kinds of archives. It works for categories, tags, and custom taxonomies.
No. It only works on term archive pages.
Pass false as the second argument: single_term_title( '', false ).
No. The prefix is added only when the name is printed.

Next: tag_description()

Return the description of a tag (current archive by default).

tag_description() 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