Displays or retrieves the current post title with optional markup.
$before
string optional Markup to prepend to the title.
Default:''
$after
string optional Markup to append to the title.
Default:''
$display
bool optional Whether to echo or return the title. Default true for echo.
Default:true
void|string Void if $display
argument is true or the title is empty, current post title if $display
is false.
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.
function the_title( $before = '', $after = '', $display = true ) {
$title = get_the_title();
if ( strlen( $title ) === 0 ) {
return;
}
$title = $before . $title . $after;
if ( $display ) {
echo $title;
} else {
return $title;
}
}
View all references View on Trac View on GitHub
Version Description 0.71 Introduced.
Example
This would print the title to the screen as an h3.
Simple use case