Disable Comments Without Plugin to block spam and keep your WordPress site clean. Here’s how to turn off comments site-wide with a simple tweak.
Step 1: Add the Comments Disable Code
Add this to your child theme’s functions.php:
// Disable comments in WordPress
add_action(‘admin_init’, function() {
// Close comments on all post types
foreach (get_post_types() as $post_type) {
if (post_type_supports($post_type, ‘comments’)) {
remove_post_type_support($post_type, ‘comments’);
remove_post_type_support($post_type, ‘trackbacks’);
}
}
});
// Hide existing comments
add_filter(‘comments_array’, ‘__return_empty_array’, 10, 2);
How It Works
This snippet removes comment and trackback support from all post types and hides any existing comments on your site.
Why Disable Comments Without Plugin?
Most sites don’t need WordPress comments anymore. Disabling them helps block spam and keeps your database lean.
Common Mistake
This won’t delete old comment data from your database. Use a cleanup plugin or a manual SQL query if you want to remove existing comments.
Pro Tip
Always place this tweak in your child theme’s functions.php so it stays active after updates.
Related Snippet
If you liked this, check out my guide on disabling the WP version number without a plugin in WordPress.