the_date() WordPress Function

The the_date() function is used to display the date on a post. The date will be displayed in the format specified in the Settings > General > Date Format.

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

Display or Retrieve the date the current post was written (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’.


Top ↑

Parameters

$format

(string)(Optional) PHP date format. Defaults to the 'date_format' option.

Default value: ''

$before

(string)(Optional) Output before the date.

Default value: ''

$after

(string)(Optional) Output after the date.

Default value: ''

$echo

(bool)(Optional) Whether to echo the date or return it.

Default value: true


Top ↑

Return

(string|void) String if retrieving.


Top ↑

Source

File: wp-includes/general-template.php

function the_date( $format = '', $before = '', $after = '', $echo = true ) {
	global $currentday, $previousday;

	$the_date = '';

	if ( is_new_day() ) {
		$the_date    = $before . get_the_date( $format ) . $after;
		$previousday = $currentday;
	}

	/**
	 * Filters the date a post was published 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 ( $echo ) {
		echo $the_date;
	} else {
		return $the_date;
	}
}


Top ↑

Changelog

Changelog
VersionDescription
0.71Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More