WordPress the_title() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints the post title

Definition

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().

Syntax

A few ways to call the_title().

WordPress
<?php
the_title( '<h1>', '</h1>' );
CallWhat 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.

Full declaration
WordPress
the_title( string $before = '', string $after = '', bool $display = true ): string|void

Parameters

ParameterDescription
$beforestring. Text or HTML before the title. Default is empty.
$afterstring. Text or HTML after the title. Default is empty.
$displaybool. true prints the title. false returns it. Default is true.

Return Value

Return ValueDescription
voidWhen $display is true, the title is printed.
stringWhen $display is false, the title is returned.

WordPress Examples

Three short examples. Each one shows the code and what it prints.

Example 1 — Print the title

Print the title in a heading.

WordPress
<h1><?php the_title(); ?></h1>

How It Works

  1. the_title() prints the title of the current post.
  2. The h1 tag is ours.
  3. Use it inside The Loop.

Example 2 — Use before and after

Let WordPress print the tags only if a title exists.

WordPress
<?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>

How It Works

  1. The first argument is printed before the title.
  2. The second argument is printed after the title.
  3. If a post has no title, no empty h2 is printed.

Frequently Asked Questions

It prints the title of the current post.
the_title() prints the title. get_the_title() returns it.
They add HTML around the title, and are printed only if the title is not empty.
Use the_title_attribute() instead. It escapes quotes.
Yes, unless you use get_the_title() with a post ID.

Browse all post functions

Open the functions index for simple guides with examples and FAQs.

Post Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful