single_cat_title()WP 0.71

Display or retrieve page title for category archive.

Useful for category template files for displaying the category page title. The prefix does not automatically place a space between the prefix, so if there should be a space, the parameter value will need to have it at the end.

No Hooks.

Return

String|null. Title when retrieving.

Usage

single_cat_title( $prefix, $display );
$prefix(string)
What to display before the title.
Default: ''
$display(true|false)
Whether to display or retrieve title.
Default: true

Examples

0

#1 Display the category or tag name on the archive page

This example will display the text "You are browsing: WordPress", where WordPress is the name of the current category:

<p><?php single_cat_title( 'You are browsing: ' ); ?>.</p>
0

#2 Write the name of the category in a variable

An example of how you can write a category name to the variable $current_cat_name, i.e. not display it on the screen (set the second parameter to 0).

$current_cat_name = single_cat_title( '', 0 );

echo $current_cat_name;

Changelog

Since 0.71 Introduced.

single_cat_title() code WP 6.5.2

function single_cat_title( $prefix = '', $display = true ) {
	return single_term_title( $prefix, $display );
}