This snippet provides a comprehensive approach to removing comment functionality while maintaining your site’s performance.
Features
- Disables comment support across all post types
- Closes comments on existing posts and pages
- Removes comment-related admin interfaces
- Disables the recent comments widget
- Removes comment functionality from the admin bar
- Zero configuration needed
- No performance impact
- Compatible with all WordPress versions 5.0+
Installation Guide
Method 1: Using functions.php (Recommended)
- Access your WordPress theme’s
functions.phpfile through FTP or your hosting file manager - Navigate to
wp-content/themes/your-theme-name/functions.php - Add the following code at the end of the file:
// Disable comments across all post types
function disable_all_comments() {
// Close comments on all post types
$post_types = get_post_types();
foreach ($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');
}
}
// Close comments on all existing posts
global $wpdb;
$wpdb->update($wpdb->posts, ['comment_status' => 'closed', 'ping_status' => 'closed'], ['post_type' => $post_types]);
// Disable comment support in admin menu
add_action('admin_menu', function() {
remove_menu_page('edit-comments.php');
});
// Disable comments widget
add_action('widgets_init', function() {
unregister_widget('WP_Widget_Recent_Comments');
});
// Remove comments from admin bar
add_action('wp_before_admin_bar_render', function() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('comments');
});
}
add_action('init', 'disable_all_comments');
Method 2: Using a Custom Plugin
- Create a new PHP file named
disable-comments.php - Add this header to the file:
3. Upload this file to wp-content/plugins/
4. Activate the plugin through the WordPress admin panel
Important Recommendations
- Backup First: Always create a backup of your WordPress site before making any code changes.
- Theme Updates: If using Method 1, note that theme updates might overwrite your changes. Consider using a child theme or Method 2 (plugin) for more permanence.
- Database Cleanup: Consider running a database cleanup to remove existing comments and related metadata after installation. You can use plugins like WP-Optimize for this purpose.
- SEO Considerations: If you had comments enabled previously, make sure to:
- Update your site’s XML sitemap
- Review and update any structured data that might reference comments
- Consider adding alternative user engagement features
5. Testing: After installation, test thoroughly:
- Check all post types (posts, pages, custom post types)
- Verify admin panel changes
Test on both desktop and mobile views - Check theme compatibility
Troubleshooting
If you encounter any issues:
- Ensure your WordPress version is 5.0 or higher
- Check for plugin conflicts, especially with other comment-related plugins
- Verify your theme’s compatibility
- Clear your WordPress cache
- If using a caching plugin, purge its cache
Performance Impact
This solution has minimal impact on your site’s performance because it:
- Uses native WordPress hooks
- Doesn’t add any database tables
- Doesn’t load any additional assets
- Removes unnecessary comment-related queries
This code is released under the GPL2 license, making it free to use and modify for both personal and commercial projects.





