Skip to content

Instantly share code, notes, and snippets.

@seezee
Last active May 6, 2021 06:33
Show Gist options
  • Save seezee/d3370afada533310d78ac673964b244a to your computer and use it in GitHub Desktop.
Save seezee/d3370afada533310d78ac673964b244a to your computer and use it in GitHub Desktop.
<?php
/**
* Displays the post modified date.
*
* @package There is no package.
*/
/**
* Returns the last modified date for the post with the <time> tag and the
* time zone.
*
* @parameter array $arr Allowed tags.
* @parameter string $tz The post modified time.
* @parameter string $ltz The local timezone offset.
* @parameter string $modified_time The unsanitized output.
* @parameter string $output The sanitized output.
*
* @return string The sanitized output.
*/
function my_post_modified_date() {
$arr = array(
'time' => array(
'datetime' => array(),
),
'small' => array(),
'i' => array(),
);
$tz = get_the_modified_time( 'T' );
if ( 'CST' === $tz ) { // Standard Time. Change to match your timezone.
$ltz = '-6:00'; // Change the offset to match your timezone.
} elseif ( 'CDT' === $tz ) { // Daylight Saving Time. Change to match your timezone.
$ltz = '-5:00'; // Change the offset to match your timezone.
} else {
$ltz = '';
}
$modified_time = '<small><i>' . esc_html_e( 'Latest revision:', 'text-domain' ) . '</i> <time datetime="' . get_the_modified_time( 'Y-m-d\TG:i:s', true, null, true ) . $ltz . '">' . get_the_modified_date() . '</time></small>';
$output = wp_kses( $modified_time, $arr );
return $output;
// Use a standard WordPress hook to output the string to your post.
// See https://developer.wordpress.org/plugins/hooks/.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment