• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (deprecated)
You are here: Home / Draft / Override WordPress Publish Date on Creation

Override WordPress Publish Date on Creation

Last updated on November 5, 2018 by Sal Ferrarello

When creating new posts for a video demonstration, I wanted to display a consistent date. While my first thought was to reset my system clock, this snippet overrides the date when the post is first created, which worked for me.

add_filter( 'wp_insert_post_data', function( $data, $postarr ) {
    $data['post_date'] = '2018-05-04 12:00:00';
    return $data;
}, 99, 2 );
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Presentation Tagged With: WordPress, WordPress Filter

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in