Resource
/
Disable WordPress Comments

Details

Category
Utilities & Scripts
Last Updated
Mar 7, 2026
Creator
Zayn Hamza

Overview

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.

Setup

00

Add External Scripts

Copy & paste the scripts before the </body> tag of your project. If you added them before for another setup, skip this step.

00

Add HTML

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.

00

Add Custom CSS

Paste the code through the page or site settings, or add it via Elementor → Custom Code (before </body>) for broader use.

00

Add Custom Javascript

Paste the script through Elementor → Custom Code (set to load after </body>) for site-wide or page-specific loading.

00

Add Custom PHP

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);
});
00

Publish and preview live

Some solutions only work on the live site. Always publish and test after each change, as results may not appear in the editor.