W3cubDocs

/WordPress

get_the_date( string $format = , int|WP_Post $post = null ): string|int|false

Retrieves the date on which the post was written.

Description

Unlike the_date() this function will always return the date.
Modify output with the ‘get_the_date’ filter.

Parameters

$formatstringoptional
PHP date format. Defaults to the 'date_format' option.

Default:''

$postint|WP_Postoptional
Post ID or WP_Post object. Default current post.

Default:null

Return

string|int|false Date the current post was written. False on failure.

Source

function get_the_date( $format = '', $post = null ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	$_format = ! empty( $format ) ? $format : get_option( 'date_format' );

	$the_date = get_post_time( $_format, false, $post, true );

	/**
	 * Filters the date a post was published.
	 *
	 * @since 3.0.0
	 *
	 * @param string|int  $the_date Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
	 * @param string      $format   PHP date format.
	 * @param WP_Post     $post     The post object.
	 */
	return apply_filters( 'get_the_date', $the_date, $format, $post );
}

Hooks

apply_filters( ‘get_the_date’, string|int $the_date, string $format, WP_Post $post )

Filters the date a post was published.

Changelog

Version Description
3.0.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_the_date