WordPress the_date() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints a date once per day

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

WordPress
<?php
the_date( 'F j, Y', '<h2>', '</h2>' );
CallWhat 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
WordPress
the_date( string $format = '', string $before = '', string $after = '', bool $display = true ): string|void

Parameters

ParameterDescription
$formatstring. A PHP date format. Default is the site date format.
$beforestring. Text or HTML before the date. Default is empty.
$afterstring. Text or HTML after the date. Default is empty.
$displaybool. true prints the date. false returns it. Default is true.

Return Value

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

WordPress
<?php while ( have_posts() ) : the_post(); ?>
  <?php the_date( 'F j, Y', '<h2>', '</h2>' ); ?>
  <h3><?php the_title(); ?></h3>
<?php endwhile; ?>

How It Works

  1. The date heading is printed for the first post of each day.
  2. The second post of November 12 prints no date.
  3. 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.

WordPress
<?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; ?>

How It Works

  1. get_the_date() returns the date every time.
  2. Both posts show the date, even on the same day.
  3. 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.

WordPress
<?php
$date = the_date( 'F j, Y', '', '', false );
if ( $date ) {
  echo '<h2>' . esc_html( $date ) . '</h2>';
}

How It Works

  1. The last argument false returns the date as a string.
  2. For a repeated day the string is empty, so the if skips it.
  3. 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

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.

9 people found this page helpful