Disallow WordPress Comments

April 23, 2024


A strong approach to globally disable comments on your WordPress site is to add this code to your functions.php. Here’s a breakdown of how each part of your code works and its implications:

Disabling Comments Support in your function.php

function disable_comments_support() {
    $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');
        }
    }
}
add_action('init', 'disable_comments_support', 100);

This part loops through all registered post types and removes the support for comments and trackbacks if they are supported. This change affects the WordPress backend, making it so that the option to leave comments or send trackbacks is removed from the user interface for all post types.

Closing Comments on the Front End:

function filter_comments_status() {
    return false;
}
add_filter('comments_open', 'filter_comments_status', 20, 2);

This filter ensures that even if a theme or a plugin attempts to check if comments are open (via comments_open() function), it will always return false, indicating that comments are closed. This affects the front-end display, preventing themes from showing comment forms.

WordPress Settings/Discussion

In your WordPress Settings you may also want to display Default Post Settings and check the box that USERS must be registered.

Other Points:

  • If your website already has comments before you add these changes, they will still appear. You will need to remove and delete them from the comments.
  • In your theme, you may have a file called comments.php – you can remove this if it’s not required.
  • Also in your single.php files you can also comment out the line // comments_template();