WordPress at a glance

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>
Works based on: get_the_title()
1 time = 0.004764s = very slow | 50000 times = 1.99s = fast | PHP 7.1.2, WP 4.7.3

No Hooks.


String/null. 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();

Список изменений

С версии 0.71 Введена.

Code of the_title() WP 5.5.1

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;

Related Functions

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 . Register