Disable comment or enable comment for all posts or pages without wordpress plugin, easy way to disable comment in wordpress.
How To Disable Comment
We will change comment status in WordPress SQL to disable or enable all posts/pages/custom post type comment. You can read this post about WordPress SQL.
Disable Comment
Copy the code and paste it in your “functions.php” file:
function WPTime_comment_status($status){ if( $status == 'close' ){ global $wpdb; $wpdb->query(" UPDATE $wpdb->posts SET comment_status = 'close' WHERE comment_status = 'open' "); update_option('default_comment_status', 'close'); } else{ global $wpdb; $wpdb->query(" UPDATE $wpdb->posts SET comment_status = 'open' WHERE comment_status = 'close' "); update_option('default_comment_status', 'open'); } }
Disable All Comments
Just paste this line in your “functions.php” file, after the function code like this:
// Disable all posts/pages/custom post type comments WPTime_comment_status('close'); // Don't forget, if has been closed, remove this line!
Enable All Comments
Just paste this line in your “functions.php” file, after the function code:
// Enable all posts/pages/custom post type comments WPTime_comment_status('open'); // Don't forget, if has been enabled, remove this line!