Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WordPress function to run when a scheduled post is published, to change the modified date/time to match. Currently, it will only show the last saved data, not its published information, unless you modify it after publishing.
// Scheduled posts should update modified date when published
function update_modified_date_to_post_date( $post ) {
$updated_data = [
'ID' => $post->ID,
'post_modified' => $post->post_date,
'post_modified_gmt' => $post->post_date_gmt
wp_update_post( $updated_data );
add_action( 'future_to_publish', 'update_modified_date_to_post_date', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment