single_post_title() WP 0.71
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.
Basis of: wp_get_document_title()
1 time = 0.00001s = speed of light | 50000 times = 0.3093s = 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. |
Code of single_post_title() single post title WP 5.6
Related Functions
From tag: title (of post page)
More from category: Posts, pages...
- edit_post_link()
- get_delete_post_link()
- get_edit_post_link()
- get_permalink()
- get_post_field()
- get_post_status()
- get_post_time()
- get_sample_permalink()
- get_the_content()
- get_the_date()
More from Template Tags: Posts, Pages, ...
- body_class()
- get_post_format()
- have_posts()
- in_the_loop()
- next_image_link()
- next_post_link()
- next_posts_link()
- post_class()