Below is a shortcode [datetime] which will output the current post object’s modification date according the the date and time format set on /wp-admin/options-general.php.
The default setting includes am/pm. See https://www.php.net/manual/en/datetime.format.php for guidelines on how to set alternative formats on that settings page, such as 24-hour time.
See the comments below for links to additional documentation & how to output the published date instead of the modified date.
The shortcode outputs the timestamp in a <p> tag. If it is to be used within content already in a paragraph or other tag, remove <p> and </p>, or remove return sprintf( and instead start the function at return wp_date(, removing one of the ending-closing-parenthesis.
<?php
/**
* [datetime]
*
* @see /wp-admin/options-general.php (For date & time format settings.)
* @see https://developer.ww.wp.xz.cn/reference/functions/wp_date/
* @see https://developer.ww.wp.xz.cn/reference/functions/get_post_timestamp/
* @see https://www.php.net/manual/en/datetime.format.php
* @see https://www.php.net/manual/en/function.sprintf.php
*/
add_shortcode(
'datetime',
function( $atts, $content, $tagname ) {
return sprintf(
'<p>%s</p>',
wp_date(
sprintf(
'%s %s',
get_option( 'date_format' ),
get_option( 'time_format' )
),
get_post_timestamp(
get_the_ID(),
'modified' // change to 'date' for published date.
)
)
);
}
);
Thread Starter
avu
(@avu)
OK, the reference {@post_modified} in the POD template will be replaced with the shortcode [datetime] whose php code you were so kind to share allows full control of the post ‘date modified’ display format.
Many thanks !