single_tag_title()WP 2.3.0

Outputs the title of the current meta-field if the tag archive page is being viewed.

Since version 3.1+, this function is identical to the functions: single_cat_title() and single_term_title().

It is more logical to use single_term_title() to get the title of tag, category, or other taxonomy archive pages.

No Hooks.

Returns

String|null. The title of the current meta-field page. If the title could not be retrieved, the function returns nothing.

Usage

<?php single_tag_title( $prefix, $display ); ?>
$prefix(string)
Text to be displayed before the title.
Default: ''
$display(boolean)
If this parameter is set to 0 (false), the function's result will be returned instead of being displayed.
Default: 1 (true)

Examples

0

#1 Header current tags with preceding text

It is assumed that we are browsing the page tags "website promotion".

<p><?php single_tag_title( 'You are viewing the tag: ' ); ?>.</p>

We get it: You are viewing the tag: Website Promotion.

0

#2 Get the title to the variable

This example shows how to get the title into the $current_tag variable instead of displaying it:

$current_tag = single_tag_title( '', 0 );

echo $current_tag;

Changelog

Since 2.3.0 Introduced.

single_tag_title() code WP 6.8.3

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