get_the_date() WordPress Function

The get_the_date() function is used to return the date of a post. The date is returned in the WordPress format specified in the Settings > General > Date Format option.

get_the_date( string $format = '', int|WP_Post $post = null ) #

Retrieve 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.


Top ↑

Parameters

$format

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

Default value: ''

$post

(int|WP_Post)(Optional) Post ID or WP_Post object. Default current post.

Default value: null


Top ↑

Return

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


Top ↑

Source

File: wp-includes/general-template.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

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