WordPress get_calendar() Function

Definition
In WordPress, get_calendar() creates a small calendar for the current month. Days that have posts are linked to their daily archive.
It is the same calendar that the Calendar widget shows. The output is an HTML table with the id wp-calendar.
Syntax
Call it with no arguments to print the calendar.
| Call | What it does |
|---|
get_calendar() | Prints the calendar with one-letter day names. |
get_calendar( false ) | Prints the calendar with three-letter day names. |
get_calendar( true, false ) | Returns the calendar as a string. |
The calendar HTML is cached. See delete_get_calendar_cache().
Full declaration
get_calendar( bool $initial = true, bool $display = true ): void|string
Parameters
| Parameter | Description |
|---|
$initial | bool. true (default) uses one-letter day names such as M, T, W. false uses three letters such as Mon, Tue. |
$display | bool. true (default) prints the calendar. false returns it as a string. |
Return Value
| Return Value | Description |
|---|
| void | When $display is true, the calendar is printed. |
| string | When $display is false, the calendar HTML is returned. |
WordPress Examples
Three short theme examples. Each one shows the code and what it prints.
Example 1 — Show the calendar
Put the calendar in a sidebar.
<aside class="widget">
<h3>Post Calendar</h3>
<?php get_calendar(); ?>
</aside>
<table id="wp-calendar" class="wp-calendar-table">
<caption>November 2026</caption>
<thead>
<tr><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr>
</thead>
...
</table>How It Works
get_calendar() prints the table.- Days with posts become links.
- The caption shows the month and year.
Example 2 — Use three-letter day names
Pass false for the first argument.
<?php get_calendar( false ); ?>
<thead>
<tr><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th><th>Sun</th></tr>
</thead>
How It Works
$initial is false.- The header cells use short names instead of one letter.
- This is easier to read on wide layouts.
Example 3 — Get the HTML as a string
Wrap the calendar in your own markup.
<?php
$calendar = get_calendar( true, false );
echo '<div class="my-calendar">' . $calendar . '</div>';
<div class="my-calendar"><table id="wp-calendar" class="wp-calendar-table">...</table></div>
How It Works
$display is false, so nothing is printed yet.- The calendar HTML is stored in
$calendar. - We echo it inside our own
div.
Frequently Asked Questions
It prints (or returns) a small HTML calendar for the current month. Days with posts link to the daily archive.
true shows one-letter day names. false shows three-letter day names.
Pass false as the second argument: get_calendar( true, false ).
The HTML is cached. WordPress clears it when you save a post. If you changed posts another way, call delete_get_calendar_cache().
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