WordPress single_term_title() Function

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

Definition

In WordPress, single_term_title() shows the name of the current term on a taxonomy archive. A term can be a category, a tag, or a term of a custom taxonomy such as "Genre".

single_cat_title() and single_tag_title() use this function behind the scenes, so it is the best choice for a template that serves many taxonomies, like taxonomy.php or archive.php.

Syntax

Use it in taxonomy.php or archive.php.

WordPress
<?php
single_term_title();
CallWhat it does
single_term_title()Prints the term name.
single_term_title( 'Topic: ' )Prints the name with a prefix.
single_term_title( '', false )Returns the name instead of printing.

It works for categories, tags, and custom taxonomy terms.

Full declaration
WordPress
single_term_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 — One heading for any term

Use it in archive.php.

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

How It Works

  1. The function checks which taxonomy the page uses.
  2. It prints the name of that term.
  3. One line works for every taxonomy.

Example 2 — Add a prefix

Print "Topic: Fiction".

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

How It Works

  1. The first argument is the prefix.
  2. Add a space at the end of it.
  3. The prefix is printed before the term name.

Example 3 — Return the name

Use the name in a page title.

WordPress
<?php
if ( is_category() || is_tag() || is_tax() ) {
  $name = single_term_title( '', false );
  echo 'Archive: ' . esc_html( $name );
}

How It Works

  1. The three conditional tags cover every taxonomy archive.
  2. false returns the term name.
  3. We escape it and print the message.

Frequently Asked Questions

It prints or returns the name of the current term on a category, tag, or custom taxonomy archive.
single_cat_title() is a shortcut for the same job on categories. single_term_title() works for any taxonomy.
On taxonomy archive pages only. Elsewhere it prints nothing.
No. The prefix is only added when the name is printed.

Next: wp_enqueue_script()

Add a JavaScript file to the page the safe WordPress way.

wp_enqueue_script() 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.

10 people found this page helpful