Home WordPress Posts Functions single_month_title() WordPress single_month_title() Function 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().
<h1>Posts from<?php single_month_title( ' ' ); ?></h1> Call What 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 single_month_title( string $prefix = '', bool $display = true ): string|false|void Parameters Parameter Description $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 Value Description void When $display is true, the text is printed. string When $display is false, the text is returned. false If the current page is not a monthly archive.
WordPress Examples Three short examples. Each one shows the code and what it prints.
1. Archive heading 2. Return the title 3. Use a dash prefix Example 1 — Archive heading Print a heading on a monthly archive.
<?php if ( is_month() ) : ?>
<h1>Posts from<?php single_month_title( ' ' ); ?></h1>
<?php endif; ?> <h1>Posts from November 2026</h1> How It Works is_month() is true on a monthly archive.single_month_title( ' ' ) prints a space, the month, a space, and the year.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.
<?php
$month = single_month_title( ' ', false );
if ( $month ) {
echo '<h1>Archive: ' . esc_html( trim( $month ) ) . '</h1>';
} <h1>Archive: November 2026</h1> How It Works The second argument false makes the function return the text. trim() removes the space at the start.esc_html() keeps the output safe.Example 3 — Use a dash prefix A prefix is repeated between the month and year.
<?php single_month_title( ' - ' ); ?> How It Works The prefix is added before the month. It is also added between the month and the year. This is why a single space is the usual choice. Frequently Asked Questions What does single_month_title() do? It prints or returns the month and year of a monthly archive page, such as November 2026.
What does it return outside a monthly archive? It returns false.
Why is the month stuck to the year? The prefix is also placed between the month and year. Pass a single space as the prefix.
How do I return it instead of printing? Pass false as the second argument.
Is there a simpler way to make archive titles? 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 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.
12 people found this page helpful
Helpful Share Copy link Suggestion