Example 1 — One heading for any term
Use it in archive.php.
<h1><?php single_term_title(); ?></h1> How It Works
- The function checks which taxonomy the page uses.
- It prints the name of that term.
- One line works for every taxonomy.

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.
Use it in taxonomy.php or archive.php.
<?php
single_term_title(); | Call | What 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.
single_term_title( string $prefix = '', bool $display = true ): string|void | Parameter | Description |
|---|---|
$prefix | string. Text to print before the name. Default is empty. |
$display | bool. true (default) prints the name. false returns it. |
| Return Value | Description |
|---|---|
| void | When $display is true, the name is printed. |
| string | When $display is false, the name is returned (without the prefix). |
Three short theme examples. Each one shows the code and what it prints.
Use it in archive.php.
<h1><?php single_term_title(); ?></h1> Print "Topic: Fiction".
<h1><?php single_term_title( 'Topic: ' ); ?></h1> Use the name in a page title.
<?php
if ( is_category() || is_tag() || is_tax() ) {
$name = single_term_title( '', false );
echo 'Archive: ' . esc_html( $name );
} false returns the term name.Add a JavaScript file to the page the safe WordPress way.
10 people found this page helpful