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
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. |
To get ISO 8601 date for meta, use
All PHP date formats can be found here: http://php.net/manual/en/function.date.php
To make the date appear as “Monday January 11, 2017”, for example, use
To make the date appear as “Wed Jan 9”, for example, use
Gets the date format in day, day symbol, short month and long year.
E.g. 15th Jan 2020
Default Usage
If you want to display the publish date in Ymd format (ex: 20191231):
If you want to show the current month’s full name and year then you can use it.
E.g. January 2020
If you need the modified date for schema purpose in ISO format
get_the_modified_date()
instead? Or perhaps you could add a paragraph explaining that this function returns the published date, whereas if one requires the last modified date, thenget_the_modified_date()
should be called. The formatting for ISO 8601 had already been explained by the note submitted by @chetan200891.