WordPress Code Reference & the_date()

What Is the WordPress Code Reference?

The WordPress Code Reference is the official, searchable index of WordPress core functions, classes, hooks (actions & filters), and methods. Each entry lists a description, parameters, return values, usage notes, version history, related links, and often examples. Developers use it to verify exact signatures and defaults, understand expected types and outputs, check deprecations/changes across versions, and copy vetted snippets instead of guessing. Keeping it open while building themes/plugins helps prevent bugs and speeds up development.

Documenting the_date()

the_date() displays (or returns) the date for the current post inside The Loop and, by design, only outputs once per date group. This avoids repeating the same date for consecutive posts that share a date. If you need the date on every post row, use get_the_date() or the_time() instead.

the_date( string $format = '',
         string $before = '',
         string $after  = '',
         bool   $echo   = true );

Parameters: $format is a PHP date()-style pattern (falls back to the site's Settings → General → Date Format if empty); $before and $after wrap the output (useful for HTML like headings/spans); $echo prints by default, or returns the string when false.

<?php if ( have_posts() ) :
  while ( have_posts() ) : the_post();
    the_date( 'F j, Y', '<h3 class="post-date">', '</h3>' );
    ?>
    <article>
      <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
      <div class="entry"><?php the_excerpt(); ?></div>
    </article>
  <?php endwhile; endif; ?>

Note: Expecting a date for each post? Use echo get_the_date('F j, Y'); inside the loop.

the_date() Format Parameters

The $format argument accepts standard PHP date() tokens. Common examples:

'F j, Y'    →  March 10, 2025
'Y-m-d'     →  2025-03-10
'l, F j'    →  Monday, March 10
'M j, g:ia' →  Mar 10, 7:05pm
  • Y = 4‑digit year; y = 2‑digit year
  • m/n = month (01–12 / 1–12); F/M = month name (full/short)
  • d/j = day (01–31 / 1–31)
  • l/D = weekday (full/short)
  • g/h = hour 12‑hr; G/H = hour 24‑hr
  • i = minutes; s = seconds; a/A = am/pm

If $format is empty, WordPress uses your site setting from Settings → General → Date Format.

Summary

The WordPress Code Reference is the authoritative index for core APIs and is essential for accurate, modern development. the_date() prints a grouped post date within The Loop and supports custom formatting and wrappers, but it intentionally avoids repeating the same date per group. Use get_the_date() when you need a date for every post item. Mastering the date() tokens ensures your output matches design and localization needs.