WordPress single_cat_title() Function

Definition
In WordPress, single_cat_title() gives you the name of the category on a category 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 archive pages.
Syntax
Call it on a category archive. Pass a prefix, or set display to false to get the name as a string.
single_cat_title();
single_cat_title( 'Category: ' );
$name = single_cat_title( '', false );
| Call | What it does |
|---|
single_cat_title() | Prints the category name. |
single_cat_title( 'Category: ' ) | Prints the prefix, then the name. |
single_cat_title( '', false ) | Returns the name as a string. Nothing is printed. |
Use it in category.php or archive.php. It does nothing on other pages.
Full declaration
single_cat_title( string $prefix = '', bool $display = true ): string|void
Parameters
| Parameter | Description |
|---|
$prefix | Optional. Text placed before the name when it is printed. Default is an empty string. |
$display | Optional. true prints the name (default). false returns it. |
Return Value
| Return Value | Description |
|---|
| string | The category name. Returned only when $display is false. |
| void | Nothing is returned when the name is printed, or when the page is not a category archive. |
WordPress Examples
Three short theme examples. Each one has a sample output.
Example 1 — Print the title
Show the category name in a heading.
<h1><?php single_cat_title(); ?></h1>
How It Works
- On a category archive the function prints the category name.
- Put it inside your own
h1 tag. - No
echo is needed because it prints by itself.
Example 2 — Add a prefix
Print a small label before the name.
<h1><?php single_cat_title( 'Category: ' ); ?></h1>
<h1>Category: WordPress Tips</h1>
How It Works
- The first argument is the prefix.
- WordPress prints the prefix and then the name.
- Include the space inside the prefix text.
Example 3 — Return the name
Get the name as a string and escape it.
<?php
$name = single_cat_title( '', false );
echo '<h1>Posts in ' . esc_html( $name ) . '</h1>';
?>
<h1>Posts in WordPress Tips</h1>
How It Works
false tells the function to return the name.- The name is saved in
$name. esc_html() keeps the output safe.
Frequently Asked Questions
It prints the name of the current category on a category archive page. With $display set to false, it returns the name.
No. It only works on archive pages. On a single post, use get_the_category() or the_category().
Pass false as the second argument: single_cat_title( '', false ).
No. The prefix is added only when the name is printed.
single_cat_title() is meant for categories. single_term_title() works for categories, tags, and custom taxonomies.
About the author
Developer, cloud engineer, and technical writer
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