0

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

This working fine for me but it's disabling all the time-and-date-published.I need to apply for one particular custom post type.some one please help on this

0

I presume you want to remove the Publish: XXXXX from the sidebar like the images below.

UI with Publish Date Picker Option

TO the one below without the Publish: XXXXX

enter image description here

To do this, you would need to create a CSS File and add some code to your theme's functions.php file, or your plugin's file.

The CSS File will have the following code,

.edit-post-post-publish {
    display: none;
}

Name the css file delete-published-on-from-gutenberg.css and place it in the css folder in your theme, or plugin.

Next, you need to add the following code to the theme's function.php file or the plugin's file.

function delete_published_on_from_gutenberg() {
    $your_post_type = "book"; // Change this to your post type.
    $current_post_type = get_current_screen();

    if($current_post_type == $your_post_type) {
        wp_enqueue_style( "delete-published-on-from-gutenberg", get_template_directory_uri() . "/css/delete-published-on-from-gutenberg.css", array(), "1.0" );
        // Replace get_template_directory_uri() . "/css/delete-published-on-from-gutenberg.css" with plugin_dir_url( __FILE__ ) . "css/delete-published-on-from-gutenberg.css" if you are creating a plugin.
    }
}
add_action( "enqueue_block_editor_assets", "delete_published_on_from_gutenberg" );
0

Have you tried a conditional if loop inside that?

function deny_post_date_change( $data, $postarr ) {

    $your_post_type = "post";

    if( $data["post_type"] == $your_post_type ) {

        unset( $data['post_date'] );
        unset( $data['post_date_gmt'] );
        return $data;

    } else {

        return $data;

    }

}
add_filter( "wp_insert_post_data", "deny_post_date_change", 0, 2 );
  • But How can i remove from UI @Anteraez.css part – Musni Oct 15 at 9:37
  • @Musni Please check my other answer and let me know if that's what you want, and whether it is working for you. – Anteraez Oct 15 at 10:22
  • If i put if condition , when i edit other post i'm getting error message like this The site is experiencing technical difficulties. Please check your site admin email inbox for instructions. – Musni Oct 15 at 10:35
  • @Musni It was an error on my side. I have corrected the code and also tested it on a local wordpress install. Instead of using add_action, it had be add_filter. – Anteraez Oct 15 at 10:44
  • Thank you very much it's working for me – Musni Oct 16 at 5:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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