WordPress get_calendar() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Template tag

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.

WordPress
<?php get_calendar(); ?>
CallWhat 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
WordPress
get_calendar( bool $initial = true, bool $display = true ): void|string

Parameters

ParameterDescription
$initialbool. true (default) uses one-letter day names such as M, T, W. false uses three letters such as Mon, Tue.
$displaybool. true (default) prints the calendar. false returns it as a string.

Return Value

Return ValueDescription
voidWhen $display is true, the calendar is printed.
stringWhen $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.

WordPress
<aside class="widget">
  <h3>Post Calendar</h3>
  <?php get_calendar(); ?>
</aside>

How It Works

  1. get_calendar() prints the table.
  2. Days with posts become links.
  3. The caption shows the month and year.

Example 2 — Use three-letter day names

Pass false for the first argument.

WordPress
<?php get_calendar( false ); ?>

How It Works

  1. $initial is false.
  2. The header cells use short names instead of one letter.
  3. This is easier to read on wide layouts.

Example 3 — Get the HTML as a string

Wrap the calendar in your own markup.

WordPress
<?php
$calendar = get_calendar( true, false );
echo '<div class="my-calendar">' . $calendar . '</div>';

How It Works

  1. $display is false, so nothing is printed yet.
  2. The calendar HTML is stored in $calendar.
  3. 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().

Next: get_current_blog_id()

Get the ID of the current site (always 1 on a single site install).

get_current_blog_id() 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.

12 people found this page helpful