WordPress at Your Fingertips

the_title() WP 0.71

Display the current post title with optional HTML markup. It is accepted to use inside the WordPress Loop.

If the post is protected or private and you are on front-end, then "Protected" or "Private" will be displayed before the post title.

When you need to add post title to an HTML tag attribute, use the_title_attribute() function instead of the_title() or get_the_title().

<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
1 time — 0.004764 sec (very slow) | 50000 times — 1.99 sec (fast) | PHP 7.1.2, WP 4.7.3

No Hooks.


null|String. null when the result is displayed ($echo=true). String when ($echo=false).


the_title( $before, $after, $echo );
Text / HTML code to be placed before the title.
Default: ''
Text / HTML code to be placed after the title.
Default: ''

Whether to echo or return the title.

  • true — display
  • false — return for further processing.

Default: true


#1 Display the title of the post in the html tag H3

<?php the_title('<h3>', '</h3>'); ?>


<h3><?php the_title(); ?></h3>

#2 Get the title of the post in the variable

To get the value to use it in PHP, specify the third parameter $echo as false or 0. Or use the get_the_title()

$title = the_title( '', '', 0 );

// or
$title = get_the_title();


Since 0.71 Introduced.

Code of the_title() WP 5.7.2

function the_title( $before = '', $after = '', $echo = true ) {
	$title = get_the_title();

	if ( strlen( $title ) == 0 ) {

	$title = $before . $title . $after;

	if ( $echo ) {
		echo $title;
	} else {
		return $title;

From tag: title (of post page)

More from category: Posts, pages...

More from Template Tags: Posts, Pages, ...

vladlu 100vlad.lu
Editors: Kama 100
No comments
    Log In