WordPress single_post_title() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Archive title

Definition

In WordPress, single_post_title() shows the title of the current post or Page. It works outside the loop, which makes it useful in headers and the page title.

It also works on the blog posts page when you use a static front page, where it prints the title of that Posts page.

Syntax

Call it in a header or any template file.

WordPress
<?php
single_post_title();
CallWhat it does
single_post_title()Prints the current post or Page title.
single_post_title( 'You are reading: ' )Prints the title with a prefix.
single_post_title( '', false )Returns the title instead of printing.

Inside the loop, the_title() is the usual choice.

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

Parameters

ParameterDescription
$prefixstring. Text to print before the title. Default is empty.
$displaybool. true (default) prints the title. false returns it.

Return Value

Return ValueDescription
voidWhen $display is true, the title is printed.
stringWhen $display is false, the title is returned (without the prefix).

WordPress Examples

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

Example 1 — Print the post title

Show the title in the page header.

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

How It Works

  1. The visitor is on a single post.
  2. The function prints the post title.
  3. No loop is needed.

Example 2 — Add a prefix

Print "Now reading: Hello World".

WordPress
<p><?php single_post_title( 'Now reading: ' ); ?></p>

How It Works

  1. The first argument is printed before the title.
  2. Add the space yourself.
  3. The result is a friendly label.

Example 3 — Return the title

Use the title in an attribute.

WordPress
<?php
$title = single_post_title( '', false );
echo '<meta name="x-post-title" content="' . esc_attr( $title ) . '">';

How It Works

  1. false returns the title as a string.
  2. esc_attr() makes it safe for an attribute.
  3. The tag is printed with the title inside.

Frequently Asked Questions

It prints or returns the title of the current post or Page from the main query.
single_post_title() works outside the loop. the_title() works inside the loop.
It prints the title of the Page you chose as the Posts page in Settings > Reading.
No. The prefix is only used when printing.

Next: single_tag_title()

Print or return the name of the current tag on a tag archive.

single_tag_title() tutorial →

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.

8 people found this page helpful