Skip to content

Instantly share code, notes, and snippets.

@cabrailsford
Last active July 14, 2020 17:23
Show Gist options
  • Save cabrailsford/71879eba252b2b1665a7d9fb69497bbb to your computer and use it in GitHub Desktop.
Save cabrailsford/71879eba252b2b1665a7d9fb69497bbb to your computer and use it in GitHub Desktop.
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.
<?php
// 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