Why Disable Comments?

WordPress allows comments by default on posts, which can be great for engagement. However, in some cases, you may want to disable comments entirely. Here are some reasons why:

  • Prevent spam comments from bots or users.
  • Improve website speed and performance.
  • Maintain a professional website without unnecessary discussions.
  • Avoid moderation efforts and reduce maintenance time.
  • Enhance security by eliminating potential vulnerabilities in the comments section.

Disable Comments All Over WordPress Using PHP

To completely disable comments across your WordPress site, follow these steps:

Install “Koolak Custom Code” Plugin

Instead of modifying your theme’s functions.php file (which can be overwritten by theme updates), use the Koolak Custom Code plugin. This plugin allows you to add custom code safely.

  1. Go to Plugins > Add New in your WordPress dashboard.
  2. click on upload plugin button
  3. Download Custom Code Plugin and upload the zip
  4. Activate the plugin.

Disable Comments in WordPress - Download Plugin

Add This Code

Once the plugin is installed and activated, add the following PHP code to disable comments completely:

add_action('admin_init', function () {
    // Redirect any user trying to access comments page
    global $pagenow;
    
    if ($pagenow === 'edit-comments.php') {
        wp_safe_redirect(admin_url());
        exit;
    }

    // Remove comments metabox from dashboard
    remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');

    // Disable support for comments and trackbacks in 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');
        }
    }
});

// Close comments on the front-end
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);

// Hide existing comments
add_filter('comments_array', '__return_empty_array', 10, 2);

// Remove comments page in menu
add_action('admin_menu', function () {
    remove_menu_page('edit-comments.php');
});

// Remove comments links from admin bar
add_action('init', function () {
    if (is_admin_bar_showing()) {
        remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
    }
});

Disable Comments for Future Posts Without Code (Just for Future Posts)

Disable Comments in WordPress - Future posts

If you want to disable comments only for future posts without modifying any code, follow these steps:

  1. Go to Settings > Discussion in the WordPress dashboard.
  2. Uncheck the box that says Allow people to post comments on new articles.
  3. Click Save Changes.

This will disable comments for all future posts, but existing posts will still have comments enabled unless you edit them individually.

Disable Comments on Individual Posts

Disable Comments in WordPress - Quick Edit

If you only want to disable comments on specific posts, you can do it quickly using the Quick Edit feature:

  1. Navigate to Posts > All Posts in your dashboard.
  2. Hover over the post you want to edit and click Quick Edit.
  3. Uncheck the Allow Comments option.
  4. Click Update to save the changes.

This method is useful if you want selective control over which posts allow comments.

Conclusion

Disabling comments in WordPress can help improve site performance, reduce spam, and maintain a cleaner website. Whether you choose to disable comments globally using PHP, turn them off for future posts, or manage them individually using Quick Edit, WordPress provides flexible options to control comments effectively.

Leave a Reply

Your email address will not be published. Required fields are marked *