: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$allowed .= ' ' . $attribute . '=""';
return htmlentities( $allowed );
* Outputs the date in iso8601 format for xml files.
function the_date_xml() {
echo mysql2date( 'Y-m-d', get_post()->post_date, false );
* Displays or retrieves the date the current post was written (once per date)
* Will only output the date if the current post's date is different from the
* 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'.
* @global string $currentday The day of the current post in the loop.
* @global string $previousday The day of the previous post in the loop.
* @param string $format Optional. PHP date format. Defaults to the 'date_format' option.
* @param string $before Optional. Output before the date. Default empty.
* @param string $after Optional. Output after the date. Default empty.
* @param bool $display Optional. Whether to echo the date or return it. Default true.
* @return string|void String if retrieving.
function the_date( $format = '', $before = '', $after = '', $display = true ) {
global $currentday, $previousday;
$the_date = $before . get_the_date( $format ) . $after;
$previousday = $currentday;
* Filters the date a post was published for display.
* @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 );
* Retrieves the date on which the post was written.
* Unlike the_date() this function will always return the date.
* Modify output with the {@see 'get_the_date'} filter.
* @param string $format Optional. PHP date format. Defaults to the 'date_format' option.
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
* @return string|int|false Date the current post was written. False on failure.
function get_the_date( $format = '', $post = null ) {
$post = get_post( $post );
$_format = ! empty( $format ) ? $format : get_option( 'date_format' );
$the_date = get_post_time( $_format, false, $post, true );
* Filters the date a post was published.
* @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 );
* Displays the date on which the post was last modified.
* @param string $format Optional. PHP date format. Defaults to the 'date_format' option.
* @param string $before Optional. Output before the date. Default empty.
* @param string $after Optional. Output after the date. Default empty.
* @param bool $display Optional. Whether to echo the date or return it. Default true.
* @return string|void String if retrieving.
function the_modified_date( $format = '', $before = '', $after = '', $display = true ) {
$the_modified_date = $before . get_the_modified_date( $format ) . $after;
* Filters the date a post was last modified for display.
* @param string|false $the_modified_date The last modified date or false if no post is found.
* @param string $format PHP date format.
* @param string $before HTML output before the date.
* @param string $after HTML output after the date.
$the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $format, $before, $after );
return $the_modified_date;
* Retrieves the date on which the post was last modified.
* @since 4.6.0 Added the `$post` parameter.
* @param string $format Optional. PHP date format. Defaults to the 'date_format' option.
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
* @return string|int|false Date the current post was modified. False on failure.
function get_the_modified_date( $format = '', $post = null ) {
$post = get_post( $post );
// For backward compatibility, failures go through the filter below.
$_format = ! empty( $format ) ? $format : get_option( 'date_format' );
$the_time = get_post_modified_time( $_format, false, $post, true );
* Filters the date a post was last modified.
* @since 4.6.0 Added the `$post` parameter.
* @param string|int|false $the_time The formatted date or false if no post is found.
* @param string $format PHP date format.
* @param WP_Post|null $post WP_Post object or null if no post is found.
return apply_filters( 'get_the_modified_date', $the_time, $format, $post );
* Displays the time at which the post was written.
* @param string $format Optional. Format to use for retrieving the time the post
* was written. Accepts 'G', 'U', or PHP date format.
* Defaults to the 'time_format' option.
function the_time( $format = '' ) {
* Filters the time a post was written for display.
* @param string $get_the_time The formatted time.
* @param string $format Format to use for retrieving the time the post
* was written. Accepts 'G', 'U', or PHP date format.
echo apply_filters( 'the_time', get_the_time( $format ), $format );
* Retrieves the time at which the post was written.
* @param string $format Optional. Format to use for retrieving the time the post
* was written. Accepts 'G', 'U', or PHP date format.
* Defaults to the 'time_format' option.
* @param int|WP_Post $post Post ID or post object. Default is global `$post` object.
* @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
function get_the_time( $format = '', $post = null ) {
$post = get_post( $post );
$_format = ! empty( $format ) ? $format : get_option( 'time_format' );
$the_time = get_post_time( $_format, false, $post, true );
* Filters the time a post was written.
* @param string|int $the_time Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
* @param string $format Format to use for retrieving the time the post
* was written. Accepts 'G', 'U', or PHP date format.
* @param WP_Post $post Post object.
return apply_filters( 'get_the_time', $the_time, $format, $post );
* Retrieves the time at which the post was written.
* @param string $format Optional. Format to use for retrieving the time the post
* was written. Accepts 'G', 'U', or PHP date format. Default 'U'.
* @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
* @param int|WP_Post $post Post ID or post object. Default is global `$post` object.
* @param bool $translate Whether to translate the time string. Default false.
* @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
function get_post_time( $format = 'U', $gmt = false, $post = null, $translate = false ) {
$post = get_post( $post );
$source = ( $gmt ) ? 'gmt' : 'local';
$datetime = get_post_datetime( $post, 'date', $source );
if ( false === $datetime ) {
if ( 'U' === $format || 'G' === $format ) {
$time = $datetime->getTimestamp();
// Returns a sum of timestamp with timezone offset. Ideally should never be used.
$time += $datetime->getOffset();
} elseif ( $translate ) {
$time = wp_date( $format, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null );
$datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
$time = $datetime->format( $format );
* Filters the localized time a post was written.
* @param string|int $time Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
* @param string $format Format to use for retrieving the time the post was written.
* Accepts 'G', 'U', or PHP date format.
* @param bool $gmt Whether to retrieve the GMT time.
return apply_filters( 'get_post_time', $time, $format, $gmt );
* Retrieves post published or modified time as a `DateTimeImmutable` object instance.
* The object will be set to the timezone from WordPress settings.
* For legacy reasons, this function allows to choose to instantiate from local or UTC time in database.
* Normally this should make no difference to the result. However, the values might get out of sync in database,
* typically because of timezone setting changes. The parameter ensures the ability to reproduce backwards
* compatible behaviors in such cases.
* @param int|WP_Post $post Optional. Post ID or post object. Default is global `$post` object.
* @param string $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'.
* @param string $source Optional. Local or UTC time to use from database. Accepts 'local' or 'gmt'.
* @return DateTimeImmutable|false Time object on success, false on failure.
function get_post_datetime( $post = null, $field = 'date', $source = 'local' ) {
$post = get_post( $post );
$wp_timezone = wp_timezone();
if ( 'gmt' === $source ) {
$time = ( 'modified' === $field ) ? $post->post_modified_gmt : $post->post_date_gmt;
$timezone = new DateTimeZone( 'UTC' );
$time = ( 'modified' === $field ) ? $post->post_modified : $post->post_date;
$timezone = $wp_timezone;
if ( empty( $time ) || '0000-00-00 00:00:00' === $time ) {
$datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', $time, $timezone );
if ( false === $datetime ) {
return $datetime->setTimezone( $wp_timezone );
* Retrieves post published or modified time as a Unix timestamp.
* Note that this function returns a true Unix timestamp, not summed with timezone offset
* like older WP functions.
* @param int|WP_Post $post Optional. Post ID or post object. Default is global `$post` object.
* @param string $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'.
* @return int|false Unix timestamp on success, false on failure.
function get_post_timestamp( $post = null, $field = 'date' ) {
$datetime = get_post_datetime( $post, $field );
if ( false === $datetime ) {
return $datetime->getTimestamp();
* Displays the time at which the post was last modified.
* @param string $format Optional. Format to use for retrieving the time the post
* was modified. Accepts 'G', 'U', or PHP date format.
* Defaults to the 'time_format' option.
function the_modified_time( $format = '' ) {
* Filters the localized time a post was last modified, for display.
* @param string|false $get_the_modified_time The formatted time or false if no post is found.
* @param string $format Format to use for retrieving the time the post
* was modified. Accepts 'G', 'U', or PHP date format.
echo apply_filters( 'the_modified_time', get_the_modified_time( $format ), $format );
* Retrieves the time at which the post was last modified.
* @since 4.6.0 Added the `$post` parameter.
* @param string $format Optional. Format to use for retrieving the time the post
* was modified. Accepts 'G', 'U', or PHP date format.
* Defaults to the 'time_format' option.
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
* @return string|int|false Formatted date string or Unix timestamp. False on failure.
function get_the_modified_time( $format = '', $post = null ) {
$post = get_post( $post );
// For backward compatibility, failures go through the filter below.
$_format = ! empty( $format ) ? $format : get_option( 'time_format' );
$the_time = get_post_modified_time( $_format, false, $post, true );
* Filters the localized time a post was last modified.
* @since 4.6.0 Added the `$post` parameter.
* @param string|int|false $the_time The formatted time or false if no post is found.
* @param string $format Format to use for retrieving the time the post
* was modified. Accepts 'G', 'U', or PHP date format.
* @param WP_Post|null $post WP_Post object or null if no post is found.
return apply_filters( 'get_the_modified_time', $the_time, $format, $post );
* Retrieves the time at which the post was last modified.
* @param string $format Optional. Format to use for retrieving the time the post
* was modified. Accepts 'G', 'U', or PHP date format. Default 'U'.
* @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
* @param int|WP_Post $post Post ID or post object. Default is global `$post` object.
* @param bool $translate Whether to translate the time string. Default false.
* @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
function get_post_modified_time( $format = 'U', $gmt = false, $post = null, $translate = false ) {
$post = get_post( $post );
$source = ( $gmt ) ? 'gmt' : 'local';
$datetime = get_post_datetime( $post, 'modified', $source );
if ( false === $datetime ) {
if ( 'U' === $format || 'G' === $format ) {
$time = $datetime->getTimestamp();
// Returns a sum of timestamp with timezone offset. Ideally should never be used.
$time += $datetime->getOffset();
} elseif ( $translate ) {
$time = wp_date( $format, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null );
$datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
$time = $datetime->format( $format );
* Filters the localized time a post was last modified.
* @param string|int $time Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
* @param string $format Format to use for retrieving the time the post was modified.
* Accepts 'G', 'U', or PHP date format. Default 'U'.
* @param bool $gmt Whether to retrieve the GMT time. Default false.
return apply_filters( 'get_post_modified_time', $time, $format, $gmt );
* Displays the weekday on which the post was written.
* @global WP_Locale $wp_locale WordPress date and time locale object.
$the_weekday = $wp_locale->get_weekday( get_post_time( 'w', false, $post ) );
* Filters the weekday on which the post was written, for display.