
This snippet completely disables the WordPress comment system across your site.
It removes comment support from all post types, hides the comments section from the WordPress admin dashboard, removes the comment icon from the admin bar, and blocks direct access to the comments page in the admin area. It also disables comment-related REST API endpoints and comment feeds so they cannot be accessed externally.
Most modern websites do not rely on WordPress comments, so disabling them helps keep the admin area cleaner, removes unused features, and slightly reduces the site’s attack surface.
Copy & paste the scripts before the </body> tag of your project. If you added them before for another setup, skip this step.
Place the code in an HTML widget or add it through Elementor → Custom Code (before the closing </body> tag) either globally or only on selected pages.
Paste the code through the page or site settings, or add it via Elementor → Custom Code (before </body>) for broader use.
Paste the script through Elementor → Custom Code (set to load after </body>) for site-wide or page-specific loading.
Place the PHP snippet in your theme’s functions.php file or add it using a code snippets plugin to enable the logic.
// Remove comment support from all post types
add_action('init', function () {
foreach (get_post_types() as $type) {
remove_post_type_support($type, 'comments');
remove_post_type_support($type, 'trackbacks');
}
});
// Remove comments menu from admin
add_action('admin_menu', function () {
remove_menu_page('edit-comments.php');
});
// Remove comments icon from admin bar
add_action('admin_bar_menu', function ($bar) {
$bar->remove_node('comments');
}, 999);
// Block comments admin page
add_action('admin_init', function () {
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}
});
// Disable comment REST endpoints
add_filter('rest_endpoints', function ($endpoints) {
foreach ($endpoints as $route => $data) {
if (strpos($route, 'comments') !== false) {
unset($endpoints[$route]);
}
}
return $endpoints;
});
// Disable comment feeds
add_action('init', function () {
remove_action('wp_head', 'feed_links_extra', 3);
});Some solutions only work on the live site. Always publish and test after each change, as results may not appear in the editor.