WordPress the_date() Function

Definition
In WordPress, the_date() prints the publish date of the current post. It is meant for lists where posts are grouped by day.
Be careful: it prints the date only once for each day. If two posts share a day, the second one prints nothing.
Syntax
A few ways to call the_date().
<?php
the_date( 'F j, Y', '<h2>', '</h2>' );
| Call | What it does |
|---|
the_date() | Print the date in the site format. |
the_date( 'F j, Y' ) | Print the date in your own format. |
the_date( 'F j, Y', '<h2>', '</h2>' ) | Wrap the date in a heading. |
get_the_date() | Always returns the date. Better for most themes. |
It prints the date only for the first post of each day. Use get_the_date() when you want the date for every post.
Full declaration
the_date( string $format = '', string $before = '', string $after = '', bool $display = true ): string|void
Parameters
| Parameter | Description |
|---|
$format | string. A PHP date format. Default is the site date format. |
$before | string. Text or HTML before the date. Default is empty. |
$after | string. Text or HTML after the date. Default is empty. |
$display | bool. true prints the date. false returns it. Default is true. |
Return Value
| Return Value | Description |
|---|
| void | When $display is true, the date is printed. |
| string | When $display is false, the date is returned. |
WordPress Examples
Three short examples. Each one shows the code and what it prints.
Example 1 — Print a date heading
Group posts by day with a date heading.
<?php while ( have_posts() ) : the_post(); ?>
<?php the_date( 'F j, Y', '<h2>', '</h2>' ); ?>
<h3><?php the_title(); ?></h3>
<?php endwhile; ?>
<h2>November 12, 2026</h2>
<h3>Second post today</h3>
<h3>First post today</h3>
<h2>November 11, 2026</h2>
<h3>A post from yesterday</h3>
How It Works
- The date heading is printed for the first post of each day.
- The second post of November 12 prints no date.
- This is the "once per day" behavior.
Example 2 — Show a date for every post
Use get_the_date() so each post has a date.
<?php while ( have_posts() ) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<p><?php echo esc_html( get_the_date( 'F j, Y' ) ); ?></p>
<?php endwhile; ?>
<h3>Second post today</h3>
<p>November 12, 2026</p>
<h3>First post today</h3>
<p>November 12, 2026</p>
How It Works
get_the_date() returns the date every time.- Both posts show the date, even on the same day.
- This is what most themes want.
Example 3 — Return the date
Set $display to false to return the date. It is still empty for repeated days.
<?php
$date = the_date( 'F j, Y', '', '', false );
if ( $date ) {
echo '<h2>' . esc_html( $date ) . '</h2>';
}
<h2>November 12, 2026</h2>
How It Works
- The last argument
false returns the date as a string. - For a repeated day the string is empty, so the
if skips it. esc_html() makes the date safe to print.
Frequently Asked Questions
It prints the publish date of the current post, but only once for each day in a loop.
Both posts were published on the same day. the_date() prints the date only for the first one.
Use get_the_date() or the_time().
Pass a PHP date format as the first argument, for example F j, Y.
Pass false as the fourth argument.
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.
9 people found this page helpful