WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/the title

Description

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.

Usage

 <?php the_title$before$after$echo ); ?> 

Parameters

$before
(string) (optional) Text to place before the title.
Default: None
$after
(string) (optional) Text to place after the title.
Default: None
$echo
(Boolean) (optional) Display the title (TRUE) or return it for use in PHP (FALSE).
Default: TRUE

Example

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

This would print the title to the screen as an h3.

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.

Notes

Change Log

Since: 0.71

Source File

the_title() is located in wp-includes/post-template.php.

Related

See also index of Function Reference and index of Template Tags.