Any way to filter/change the display time only on the front-end with hook?
Unfortunately, I can’t adjust the timezone in General>Settings because it sets imported posts using Zulu as scheduled instead of published. I can keep the UTC 0 in General>Settings, but I need a way to display this time in a specific time zone on the front end.
Yes, I’ve checked the codex, but as I understand it, that’s how to change the formatting, and not how to adjust the time. If it can do, that’s great, I just don’t understand how. Thanks!
Found this. Modified a bit to offset in hours, and it sorta works, not totally though… does weird stuff with the time if it’s close to midnight.
Original here
function cc_time_machine( $formatted, $format ) {
$offset = -3; // Offset in hours, can be negative.
if ( $offset ) {
global $post;
$timestamp = get_post_time( 'U', true, $post ); // UTC timestamp with GMT offset included.
$adjusted = $timestamp + ( (int) $offset * HOUR_IN_SECONDS );
return date( $format, $adjusted );
}
// If option doesn't exist, then just return it unmodified.
return $formatted;
}
add_filter( 'get_the_time', 'cc_time_machine', 10, 2 );