Title: the_title
Published: April 25, 2014
Last modified: February 24, 2026

---

# the_title( string $before, string $after, bool $display = true ): void|string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#wp--skip-link--target)

Displays or retrieves the current post title with optional markup.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#parameters)󠁿

 `$before`stringoptional

Markup to prepend to the title. Default empty.

`$after`stringoptional

Markup to append to the title. Default empty.

`$display`booloptional

Whether to echo or return the title. Default true for echo.

Default:`true`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#return)󠁿

 void|string Void if `$display` argument is true or the title is empty, current 
post title if `$display` is false.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#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](https://developer.wordpress.org/reference/functions/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()](https://developer.wordpress.org/reference/functions/the_content/),
the output of [the_title()](https://developer.wordpress.org/reference/functions/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?”](https://make.wordpress.org/core/handbook/testing/reporting-security-vulnerabilities/#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()](https://developer.wordpress.org/reference/functions/the_title/)
is used. For this reason, do not write code that allows untrusted users to create
post titles.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#source)󠁿

    ```php
    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](https://developer.wordpress.org/reference/files/wp-includes/post-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/post-template.php#L43)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/post-template.php#L43-L57)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#related)󠁿

| Uses | Description | 
| [get_the_title()](https://developer.wordpress.org/reference/functions/get_the_title/)`wp-includes/post-template.php` |

Retrieves the post title.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#changelog)󠁿

| Version | Description | 
| [0.71](https://developer.wordpress.org/reference/since/0.71/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#comment-content-456)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/the_title/#comment-456)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title%2F%23comment-456)
     Vote results for this note: 16[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title%2F%23comment-456)
 4.  **Example**
 5.      ```php
         <?php the_title( '<h3>', '</h3>' ); ?>
         ```
     
 6.  This would print the title to the screen as an h3.
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title%2F%3Freplytocom%3D456%23feedback-editor-456)
 8.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/the_title/?output_format=md#comment-content-5138)
 9.    [Muhammad Ayoub](https://profiles.wordpress.org/mohammadayoub96/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/the_title/#comment-5138)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title%2F%23comment-5138)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title%2F%23comment-5138)
 11. Simple use case
 12.     ```php
         <?php
         the_title(
           sprintf( '<h2 class="card-title h4"><a href="%s" rel="bookmark">', esc_attr( esc_url( get_permalink() ) ) ),
           '</a></h2>'
         );
         ?>
         ```
     
 13.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title%2F%3Freplytocom%3D5138%23feedback-editor-5138)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_title%2F)
before being able to contribute a note or feedback.