single_cat_title()WP 0.71

Displays the title of the category or tag. Used outside the loop. Intended for archive pages.

If this function is used on tag pages, the title of the current tag will be displayed instead of the category title.

Used outside the WordPress Loop.

No Hooks.

Returns

String|null. String: text, category title. Or NULL if there is no title or it could not be retrieved.

Usage

<?php single_cat_title( $prefix, $display ); ?>
$prefix(string)
Text that will be placed before the title.
Default: ''
$display(boolean)
Display on screen (1) or return for processing (0).
Default: 1 (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.8.1

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