Example 1 — Print the title
Print the title in a heading.
<h1><?php the_title(); ?></h1> How It Works
the_title()prints the title of the current post.- The
h1tag is ours. - Use it inside The Loop.

In WordPress, the_title() prints the title of the current post. It is one of the most used template tags, and it works inside The Loop.
To get the title as text without printing, use get_the_title().
A few ways to call the_title().
<?php
the_title( '<h1>', '</h1>' ); | Call | What it does |
|---|---|
the_title() | Print the title. |
the_title( '<h1>', '</h1>' ) | Print the title inside a heading. |
the_title( '', '', false ) | Return the title instead of printing. |
get_the_title() | Return the title. Escape it when you print. |
It prints the title. The before and after text is printed only if the title is not empty.
the_title( string $before = '', string $after = '', bool $display = true ): string|void | Parameter | Description |
|---|---|
$before | string. Text or HTML before the title. Default is empty. |
$after | string. Text or HTML after the title. Default is empty. |
$display | bool. true prints the title. false returns it. Default is true. |
| Return Value | Description |
|---|---|
| void | When $display is true, the title is printed. |
| string | When $display is false, the title is returned. |
Three short examples. Each one shows the code and what it prints.
Print the title in a heading.
<h1><?php the_title(); ?></h1> the_title() prints the title of the current post.h1 tag is ours.Let WordPress print the tags only if a title exists.
<?php the_title( '<h2 class="entry-title">', '</h2>' ); ?> h2 is printed.Link the title to the post.
<h2>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h2> the_permalink() prints the link to the post.the_title() prints the link text.Open the functions index for simple guides with examples and FAQs.
13 people found this page helpful