WordPress single_post_title() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints or returns a title

Definition

In WordPress, single_post_title() shows the title of the current single post or page. It is often used in header.php to build the page title.

It reads the main query, so you do not need The Loop.

Syntax

A few ways to call single_post_title().

WordPress
<title><?php single_post_title( '', true ); ?></title>
CallWhat it does
single_post_title()Print the title.
single_post_title( 'Reading: ' )Print the title with text in front.
single_post_title( '', false )Return the title instead of printing.

It uses the main query, so it shows the title of the post or page the visitor opened, even outside The Loop.

Full declaration
WordPress
single_post_title( string $prefix = '', bool $display = true ): string|void

Parameters

ParameterDescription
$prefixstring. Text placed before the title. Default is empty.
$displaybool. true prints the result. 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 page title

Use it in a heading on a single post.

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

How It Works

  1. The function prints the title of the opened post.
  2. No Loop is needed.
  3. It is the same title shown in the editor.

Example 2 — Add a prefix

Put text in front of the title.

WordPress
<h1><?php single_post_title( 'Reading: ' ); ?></h1>

How It Works

  1. The first argument is the prefix.
  2. The prefix and the title are printed together.
  3. Use an empty string for no prefix.

Example 3 — Return the title

Set $display to false to get a string.

WordPress
<?php
$title = single_post_title( '', false );
echo '<meta property="og:title" content="' . esc_attr( $title ) . '">';

How It Works

  1. The second argument false returns the title.
  2. esc_attr() is used because the title goes into an attribute.
  3. This is handy for meta tags.

Frequently Asked Questions

It prints or returns the title of the single post or page being viewed.
No. It reads the main query.
the_title() works on the post inside The Loop. single_post_title() works on the main post of the page.
Pass false as the second argument.
It is made for single posts and pages. Use get_the_archive_title() for archives.

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