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.
Parameters
Return
(string|false) Date the current post was written. False on failure.
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 $the_date The formatted date.
* @param string $format PHP date format.
* @param int|WP_Post $post The post object or ID.
*/
return apply_filters( 'get_the_date', $the_date, $format, $post );
} Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_the_date