Random Musings

Sporadic thoughts on tech, economics, business, finance and trading

How to disable comments for all posts in self-hosted WordPress

,

To disable comments for all posts in a self-hosted WordPress site, you can use several methods. Here’s how you can achieve this:


Method 1: Disable Comments via WordPress Settings

  1. Go to Settings:
  • Log in to your WordPress admin panel.
  • Navigate to Settings > Discussion.
  1. Turn Off Commenting:
  • Uncheck “Allow people to submit comments on new posts”.
  • Scroll down and save the changes.

Note: This setting applies only to new posts, not existing ones.

  1. Disable Pingbacks and Trackbacks:
  • Uncheck “Allow link notifications from other blogs (pingbacks and trackbacks)”.

Method 2: Bulk Disable Comments for Existing Posts

  1. Go to Posts:
  • Navigate to Posts > All Posts in your admin panel.
  1. Select All Posts:
  • Click the checkbox at the top of the list to select all posts.
  • Choose “Edit” from the Bulk Actions dropdown menu and click “Apply”.
  1. Change Comment Settings:
  • In the bulk editor, set “Comments” to “Do not allow”.
  • Click “Update” to apply changes to all selected posts.

If you have many posts, repeat this process for each page of posts.


Method 3: Use a Plugin to Disable Comments

If you prefer a more automated approach, you can use a plugin. A popular option is the Disable Comments plugin.

  1. Install the Plugin:
  • Navigate to Plugins > Add New.
  • Search for “Disable Comments” and install it.
  1. Configure the Plugin:
  • After activation, go to Settings > Disable Comments.
  • Choose to disable comments everywhere (posts, pages, etc.).
  • Save the changes.

This will remove all comment-related fields and options site-wide.


Method 4: Disable Comments with Code (Advanced)

You can disable comments site-wide by adding custom code to your WordPress theme.

  1. Edit the functions.php File:
  • Navigate to Appearance > Theme Editor.
  • Open your theme’s functions.php file and add the following code:
   // Disable support for comments and trackbacks in post types
   function disable_comments_post_types_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_post_types_support');

   // Close comments on the front end
   function disable_comments_status() {
       return false;
   }
   add_filter('comments_open', 'disable_comments_status', 20, 2);
   add_filter('pings_open', 'disable_comments_status', 20, 2);

   // Redirect any comment URLs
   function disable_comments_redirect() {
       if (is_comment_feed()) {
           wp_die(__('Comments are closed.', 'disable-comments'));
       }
   }
   add_action('template_redirect', 'disable_comments_redirect');
  1. Save the File:
  • Save your changes and exit the editor.

This method disables comments site-wide, including the back end.


Method 5: Remove Comments Section from Theme

If comments still appear on posts despite being disabled, you may need to remove the comments template.

  1. Edit the Theme Files:
  • Go to Appearance > Theme Editor.
  • Open the file single.php or page.php (depending on the post type).
  1. Remove the Comments Template Call:
  • Look for the line:
    php <?php comments_template(); ?>
  • Delete or comment it out:
    php // <?php comments_template(); ?>
  1. Save the Changes:
  • Save the file, and comments will no longer appear on your posts.

Recommended Approach

  • Use Method 1 or Method 3 for simplicity.
  • Use Method 4 or Method 5 if you’re comfortable with coding and want more control.

By following these steps, you can disable comments site-wide effectively.