single_term_title()
Display or retrieve title for the current taxonomy (category, tag, etc.). Uses on term archive pages.
Useful for taxonomy term template files for displaying the taxonomy term 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.
Hooks from the function
Return
String|null
. The title of the current term (category, tag, etc.). null will be returned if no header was obtained or when the result is displayed.
Usage
<?php single_term_title( $prefix, $display ); ?>
- $prefix(string)
- What to display before the title.
Default: '' - $display(true/false)
- Whether to display or retrieve title.
Default: true
Examples
#1 Display current taxonomy title
Let's display the title of the current taxonomy term "Textbooks for students" with the preceding text "You are viewing the section: ". It can be term of build-in taxonomy or any custom taxonomy:
<h1><?php single_term_title('You are viewing the section: '); ?>.</h1>
Displays: <h1>You are viewing the section: Textbooks for students</h1>
#2 Get the term title as variable
This example shows how to obtain a term name for the variable $term_title, but not display it on the screen:
<?php $term_title = single_term_title('', 0); ?>
Changelog
Since 3.1.0 | Introduced. |