WordPress
How I Disable Comments in WordPress (Without a Plugin)
- Estimated reading time
- 1 min read
- Last updated
- Updated
If you’re not using comments on your WordPress site, there’s no reason to keep that system loaded. Instead of installing a plugin, I prefer to disable comments entirely with a few lines of code. This removes the comment feature from both the frontend and admin, keeping everything cleaner, more lightweight, and eliminating an extra area that could be targeted for spam or abuse.
If you’re not using comments on your WordPress site, there’s no reason to keep that system loaded. Instead of installing a plugin, I prefer to disable comments entirely with a few lines of code. This removes the comment feature from both the frontend and admin, keeping everything cleaner, more lightweight, and eliminating an extra area that could be targeted for spam or abuse.
Once added, comments are completely gone — no comment boxes, no dashboard section, and no leftover comment functionality running in the background.
/**
* Disable Comments Everywhere (Frontend + Admin)
*/
add_action('init', function () {
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');
}
}
});
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);
add_filter('comments_array', '__return_empty_array', 10, 2);
add_action('admin_menu', function () {
remove_menu_page('edit-comments.php');
});
add_action('admin_init', function () {
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}
});
add_action('wp_before_admin_bar_render', function () {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('comments');
});
add_filter('manage_posts_columns', function ($columns) {
unset($columns['comments']);
return $columns;
});