2

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!

1 Answer 1

0

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 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.