the_title( string $before = '', string $after = '', bool $echo = true )

Display or retrieve the current post title with optional markup.



(string) (Optional) Markup to prepend to the title.

Default value: ''


(string) (Optional) Markup to append to the title.

Default value: ''


(bool) (Optional) Whether to echo or return the title. Default true for echo.

Default value: true

Top ↑


(void|string) Void if $echo argument is true, current post title if $echo is false.

Top ↑

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.

Top ↑


File: wp-includes/post-template.php

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;

Top ↑


Version Description
0.71 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 2 content
    Contributed by Muhammad Ayoub

    There are two ways to get the post/page title for WordPress.

    `get_the_title();` and `the_title();`

    **How to use `get_the_title();`**


    **How to use `the_title();`**
    the_title(”, ”);

    **What is difference between `get_the_title();` and `the_title();`?**
    `the_title();` ill echo its value, but `get_the_title();` does not echo (just returns the value).

    This is the standard for WordPress functions: the functions that start with `the_` will echo what the corresponding function starting with `get_` returns. Other functions have a parameter to choose echo or not and others only return values.

You must log in before being able to contribute a note or feedback.