WordPress single_month_title() Function

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

Definition

In WordPress, single_month_title() shows the month and year of a monthly archive page, such as November 2026. Use it in archive.php to make a page heading.

It only gives a value on a monthly archive. On other pages it returns false.

Syntax

A few ways to call single_month_title().

WordPress
<h1>Posts from<?php single_month_title( ' ' ); ?></h1>
CallWhat it does
single_month_title( ' ' )Print the month and year with a space between them.
single_month_title( ' ', false )Return the text instead of printing.
get_the_archive_title()A ready-made archive title for any archive.

The prefix is placed before the month and between the month and the year. Use a single space ' ' to get November 2026.

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

Parameters

ParameterDescription
$prefixstring. Text placed before the month, and also between the month and year. Default is empty.
$displaybool. true prints the result. false returns it. Default is true.

Return Value

Return ValueDescription
voidWhen $display is true, the text is printed.
stringWhen $display is false, the text is returned.
falseIf the current page is not a monthly archive.

WordPress Examples

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

Example 1 — Archive heading

Print a heading on a monthly archive.

WordPress
<?php if ( is_month() ) : ?>
  <h1>Posts from<?php single_month_title( ' ' ); ?></h1>
<?php endif; ?>

How It Works

  1. is_month() is true on a monthly archive.
  2. single_month_title( ' ' ) prints a space, the month, a space, and the year.
  3. Because the space comes from the prefix, there is no space before the PHP tag.

Example 2 — Return the title

Set $display to false to keep the text in a variable.

WordPress
<?php
$month = single_month_title( ' ', false );
if ( $month ) {
  echo '<h1>Archive: ' . esc_html( trim( $month ) ) . '</h1>';
}

How It Works

  1. The second argument false makes the function return the text.
  2. trim() removes the space at the start.
  3. esc_html() keeps the output safe.

Example 3 — Use a dash prefix

A prefix is repeated between the month and year.

WordPress
<?php single_month_title( ' - ' ); ?>

How It Works

  1. The prefix is added before the month.
  2. It is also added between the month and the year.
  3. This is why a single space is the usual choice.

Frequently Asked Questions

It prints or returns the month and year of a monthly archive page, such as November 2026.
It returns false.
The prefix is also placed between the month and year. Pass a single space as the prefix.
Pass false as the second argument.
Yes. get_the_archive_title() gives a ready-made title for any archive.

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.

12 people found this page helpful