Example 1 — Category page heading
Print the name in an h1.
<h1><?php single_cat_title(); ?></h1> How It Works
- The visitor is on the "News" category archive.
- The function prints its name.
- The name goes inside the
h1.

In WordPress, single_cat_title() shows the name of the current category on a category archive page, such as "News" or "Tutorials".
It works on archive pages only. On other pages it prints nothing. The category tag is_category() is a good check to use first.
Use it in category.php or archive.php.
<?php
single_cat_title(); | Call | What it does |
|---|---|
single_cat_title() | Prints the category name. |
single_cat_title( 'Category: ' ) | Prints the name with a prefix. |
single_cat_title( '', false ) | Returns the name instead of printing. |
Related functions: single_tag_title() for tags and single_term_title() for any term.
single_cat_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.
Print the name in an h1.
<h1><?php single_cat_title(); ?></h1> h1.Print "Category: News".
<h1><?php single_cat_title( 'Category: ' ); ?></h1> Use the name in a message.
<?php
if ( is_category() ) {
$cat = single_cat_title( '', false );
echo 'Posts filed under ' . esc_html( $cat );
} is_category() makes sure we are on a category archive.false returns the name.Print or return the month and year of the current monthly archive.
6 people found this page helpful