single_post_title()
Displays or retrieve page title for post. Designed for use on individual post pages.
This is optimized for single.php template file for displaying the post title.
This function (template tag) is useful when you want to display the title of a post outside of WordPress Loop.
It does not support placing the separator after the title, but by leaving the prefix parameter empty, you can set the title separator manually. 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.
Used By: wp_get_document_title()
1 time — 0.00001 sec (speed of light) | 50000 times — 0.3093 sec (very fast)
Hooks from the function
Return
String|null
. Title when retrieving.
Usage
single_post_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 The output of the post title
Output the title of the entry in the H2 tag with the prefix text "Current post: ":
<h2><?php single_post_title('Current post: '); ?></h2>
Changelog
Since 0.71 | Introduced. |