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
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
I presume you want to remove the Publish: XXXXX from the sidebar like the images below.
TO the one below without the Publish: XXXXX
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" );
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 );