On this page
the_title( string $before = '', string $after = '', bool $echo = true ): void|string
Displays or retrieves the current post title with optional markup.
Parameters
$beforestring Optional-
Markup to prepend to the title.
Default:
'' $afterstring Optional-
Markup to append to the title.
Default:
'' $echobool Optional-
Whether to echo or return the title. Default true for echo.
Default:
true
Return
void|string Void if $echo argument is true, current post title if $echo is false.
More Information
This function displays or returns the unescaped title of the current post. This tag may only be used within The Loop, to get the title of a post outside of the loop use get_the_title. If the post is protected or private, this will be noted by the words “Protected: ” or “Private: ” prepended to the title.
Security considerations
Like the_content() , the output of the_title() is unescaped. This is considered a feature and not a bug, see the FAQ “Why are some users allowed to post unfiltered HTML?” . If the post title is <script>alert("test");</script>, then that JavaScript code will be run wherever the_title() is used. For this reason, do not write code that allows untrusted users to create post titles.
Source
File: wp-includes/post-template.php. View all references
function the_title( $before = '', $after = '', $echo = true ) {
$title = get_the_title();
if ( strlen( $title ) == 0 ) {
return;
}
$title = $before . $title . $after;
if ( $echo ) {
echo $title;
} else {
return $title;
}
}
Related
Uses
| Uses | Description |
|---|---|
| get_the_title() wp-includes/post-template.php | Retrieves the post title. |
Changelog
| Version | Description |
|---|---|
| 0.71 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/the_title