How to disable the editing of the time and date published?

There is no straightforward way to do this– at least not one that I see. That is, there don’t seem to be any hooks specifically intended for this task. You still have options though. This is what I’d do:

First, deny changes.

function deny_post_date_change( $data, $postarr ) {
  unset( $data['post_date'] );
  unset( $data['post_date_gmt'] );
  return $data;
}
add_filter( 'wp_insert_post_data', 'deny_post_date_change', 0, 2 );

You could add conditions for administrators if you wanted, or conditions for future posts, but the code as-is will completely remove any ability to edit the publication dates.

You will still see the form pieces though, so hide those with css.

function hide_publication_date_elements() { ?>
  <style type="text/css">
    a.edit-timestamp, #timestampdiv {display:none;}
  </style><?php
}
add_action( 'admin_enqueue_scripts', 'hide_publication_date_elements' );

These functions can go in your theme’s functions.php or in a plugin.

Leave a Comment