wppaste
WordPress

the_date( string $format = '', string $before = '', string $after = '', bool $display = true ): string|null

Since
0.71
Source
wp-includes/general-template.php:2686
Displays or retrieves the date of the post (once per date).

Description

Will only output the date if the current post's date is different from the previous one output. i.e. Only one date listing will show per day worth of posts shown in the loop, even if the function is called several times for each post. HTML output can be filtered with 'the_date'.Date string output can be filtered with 'get_the_date'.

Parameters

$formatstringoptional
PHP date format. Defaults to the 'date_format' option.Default: ''
$beforestringoptional
Output before the date. Default empty.Default: ''
$afterstringoptional
Output after the date. Default empty.Default: ''
$displaybooloptional
Whether to echo the date or return it. Default true.Default: true

Return

string|null
String if retrieving.

Hooks fired · 1

One hook fires while the_date() runs, in this order:

  1. apply_filters( the_date )filterline 2706 (+20 into the body)

    Filters the date of the post, for display.

Uses · 3

  • is_new_day()Determines whether the publish date of the current post in the loop is different from the publish date of the previous post in the loop.
  • get_the_date()Retrieves the date of the post.
  • apply_filters()Calls the callback functions that have been added to a filter hook.

Source

function the_date( $format = '', $before = '', $after = '', $display = true ) {	global $currentday, $previousday; 	$the_date = ''; 	if ( is_new_day() ) {		$the_date    = $before . get_the_date( $format ) . $after;		$previousday = $currentday;	} 	/**	 * Filters the date of the post, for display.	 *	 * @since 0.71	 *	 * @param string $the_date The formatted date string.	 * @param string $format   PHP date format.	 * @param string $before   HTML output before the date.	 * @param string $after    HTML output after the date.	 */	$the_date = apply_filters( 'the_date', $the_date, $format, $before, $after ); 	if ( $display ) {		echo $the_date;	} else {		return $the_date;	}}

History

Introduced in 0.71. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.0.4
Return type changed from string|void to string|null.verified against source
0.71
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/general-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.