As a site owner or junior WordPress developer, you may find yourself wanting to disable the ability to comment on your posts. Moderating comments on a WordPress website can be very time consuming with all the spam that can end up being posted to your site. Disabling comments through the WordPress dashboard can have the effect you want by eliminating the option to post comments site-wide. But comments can still be turned on on a per post basis, or someone could still inject comments into your site in malicious ways. There are several different ways to ensure comments are disabled throughout your WordPress Site.

  • Basic Discussion Settings - Provides an easy way to change basic settings through the UI. Later changes may be made through the UI in the same fashion.
    • By default, WordPress allows you to disable comments on new posts and hold comments for moderation. These setting will disable comments for all new posts, but all pasts posts will not take on these new settings. Manually visiting each old post and turning off comments may be required. Below we will show you how to force WordPress to not allow comments for new posts and require all new comments to be approved.
    • Access the settings page:
      • Visit ‘Settings’ > ‘Discussion’
        • This page shows you all the settings for comments/article settings.
    • Apply the following settings:
      • Default article settings:
        • Unchecked - Attempt to notify any blogs linked to from the article
        • Unchecked - Allow link notifications from other blogs (pingbacks and trackbacks) on new articles
        • Unchecked - Allow people to post comments on new articles
      • Other comment settings:
        • Checked - Comment author must fill out name and email
        • Checked - Users must be registered and logged in to comment
        • Checked - Automatically close comments on articles older than ‘1’ days
        • Checked - Enable threaded (nested) comments levels deep
        • Unchecked - Break comments into pages with...etc
      • Email me whenever:
        • Checked - Anyone posts a comment
        • Checked - A comment is held for moderation
      • Before a comment appears:
        • Checked - Comment must be manually approved
        • Checked - Comment author must have a previously approved comment
      • Comment moderation:
        • Hold a comment in the queue if it contains ‘2’ or more links.
    • Install a WordPress Plugin - Extends the basic configuration options with some additional tooling.
      • Visit and download the Disable Comments Plugin
      • Install the Plugin and Activate
      • Update the plugin settings by visiting ‘Settings’ > ‘Disable Comments’
      • To disable comments everywhere, select the ‘Everywhere’ option and select ‘Save Changes’
      • Note: After enabling the ‘Everywhere” option, existing comments may still appear on your site. The plugin includes a tool that will allow you to remove all existing comments from your site. Visit ‘Tools’ > ‘Delete Comments’
  • Adding code Snippets to your themes' functions .php - Prevents updating settings through the ui, which may help protect your site from malicious attacks.

Disable support for comments and trackbacks in all post types.

/*
 * Disable support for comments and trackbacks in post types.
 */
function df_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('admin_init', 'df_disable_comments_post_types_support');

Close comments on all posts for the front-end.

/*
 * Close comments and pings on all posts for the front-end.
 */
function ddw_close_all_comemnts() {
  return false;
}
add_filter('comments_open', 'ddw_close_all_comments', 20, 2);
add_filter('pings_open', 'ddw_close_all_comments', 20, 2);

Hide all existing comments on the sites front-end.

/*
 * Completely hide all comments from the front end.
 */
function ddw_hide_exsiting_comments($comments) {
  $comments = array();
  return $comments;
}
add_filter('comments_array', 'ddw_hide_existing_comments', 10, 2);

Remove comments link from WordPress Dashboard.

/*
 * Remove comments link from WordPress dashboard.
 */
function ddw_remove_comment_dashboard() {
  remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'ddw_remove_comment_dashboard');

Redirect access to comments page on the front-end.

/*
 * Redirect access to the comments page.
 */
function ddw_redirect_comment_form() {
  global $pagenow;
  if ($pagenow === 'edit-comments.php') {
    wp_redirect(admin_url()); 
    exit;
  }
}
add_action('admin_init', 'ddw_redirect_comment_form');

Remove comments metabox from Wordpress Dashboard.

/*
 * Remove comments metabox from WordPress Dashboard.
 */
function ddw_comment_metabox() {
  remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
}
add_action('admin_init', 'ddw_comment_metabox');

Remove comments links from WordPress admin bar.

/*
 * Remove comments links from Wordpress Admin bar.
 */
function ddw_comments_wordpress_admin() {
  if (is_admin_bar_showing()) {
    remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 40);
  }
}
add_action('init', 'ddw_comments_wordpress_admin');

In this article we have looked at 3 different options for disabling comments on WordPress using Discussion Settings, Disable Comments plugin and code snippets in the functions.php. With these tools, you should be able to manage comments on your site in exactly the way you want!

Written By Justin Goldman

Justin Goldman joined Colorado Digital in 2016 after graduating from Full Sail University with a degree in Web Design and Development. Since then, he’s been bringing client visions to life with his outstanding web design and development skills.