WordPress single_month_title() Function

Definition
In WordPress, single_month_title() shows the month and year of the current monthly archive, for example "November 2026".
It works on monthly archive pages. The tag is_month() tells you when you are on one.
Syntax
Pass a space as the prefix so the month and year are separated.
<?php
single_month_title( ' ' );
| Call | What it does |
|---|
single_month_title( ' ' ) | Prints "November 2026". |
single_month_title( '' ) | Prints "November2026" (no gap). |
single_month_title( ' ', false ) | Returns the text instead of printing. |
The prefix goes between the month and the year.
Full declaration
single_month_title( string $prefix = '', bool $display = true ): string|false|void
Parameters
| Parameter | Description |
|---|
$prefix | string. Text placed between the month and the year (and it is printed before the year). Use ' ' for a normal space. |
$display | bool. true (default) prints the text. false returns it. |
Return Value
| Return Value | Description |
|---|
| void | When $display is true, the month and year are printed. |
| string|false | When $display is false, the text is returned, or false if there is no month. |
WordPress Examples
Three short theme examples. Each one shows the code and what it prints.
Example 1 — Monthly archive heading
Print the month in an h1.
<h1>Posts from <?php single_month_title( ' ' ); ?></h1>
On /2026/11/:
<h1>Posts from November 2026</h1>
How It Works
- The visitor is on the November 2026 archive.
- The prefix is a space.
- The browser shows one space, so the heading reads "Posts from November 2026".
Example 2 — Return the text
Use the text in a sentence.
<?php
if ( is_month() ) {
$when = single_month_title( ' ', false );
echo 'Archive for' . esc_html( $when );
}
Archive for November 2026
How It Works
is_month() checks for a monthly archive.- The returned text starts with the prefix space.
- The sentence joins neatly.
Example 3 — A different separator
Use a dash as the prefix.
<h2><?php single_month_title( ' - ' ); ?></h2>
<h2> - November - 2026</h2>
How It Works
- The prefix is printed before the month and before the year.
- That is why the dash shows twice.
- A plain space is usually the best choice.
Frequently Asked Questions
It prints or returns the month and year of the current monthly archive, such as November 2026.
The prefix is empty. Pass a space, single_month_title( ' ' ), to separate the month and year.
On a monthly archive page. Use is_month() to check first.
It returns false when there is no month in the request.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
7 people found this page helpful