Disable comments by default in WordPress

function disable_comments_by_default( $data, $postarr ) {
if ( $data['post_type'] == 'post' && $postarr['post_status'] == 'auto-draft' ) {
$data['comment_status'] = 'closed'; // Disable comments
}
return $data;
}
add_filter( 'wp_insert_post_data', 'disable_comments_by_default', 10, 2 );

Shares