How to Completely Remove Comments From a WordPress Site

In this tutorial, we are going to show you how to completely remove/disable comments from your WordPress website. What this will do is remove the comments form on all your single pages and it will completely remove the Comments link in the WordPress Admin Dashboard. There are plugins that can do this for you but if you can perform the same thing without a plugin, it’s always better.

To do this, all you have to do is add the following code to your functions.php file:-


/**
 * Disable Comments
 */
 
 // 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 the front-end
function df_disable_comments_status() {
	return false;
}
add_filter('comments_open', 'df_disable_comments_status', 20, 2);
add_filter('pings_open', 'df_disable_comments_status', 20, 2);

// Hide existing comments
function df_disable_comments_hide_existing_comments($comments) {
	$comments = array();
	return $comments;
}
add_filter('comments_array', 'df_disable_comments_hide_existing_comments', 10, 2);

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

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

// Remove comments metabox from dashboard
function df_disable_comments_dashboard() {
	remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
}
add_action('admin_init', 'df_disable_comments_dashboard');

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

And there you have it, comments will be removed from all frontend pages and all backend pages in the CMS control panel.

Disable Comments with a Plugin

If you did want to go down the method of using a Plugin instead, we can simply activate and install the Disable Comments – Remove Comments & Protect From Spam Plugin.

To install the plugin, you can follow the below steps:

  • 1. Go to the WordPress Dashboard “Add New Plugin” section.
  • 2. Search For “Disable Comments”.
  • 3. Install, then Activate it.
  • 4. The plugin settings can be accessed via the ‘Settings’ menu in the administration area (either your site administration for single-site installs, or your network administration for network installs).

 

And that’s it! Pretty straightforward right? Let us know in the comments if this has helped you or if you require any assistance.

 

Nathan da Silva - Profile

Posted by: Nathan da Silva

Nathan is the Founder of Silva Web Designs. He is passionate about web development, website design and basically anything digital related. His main expertise is with WordPress, Magento, Shopify as well as many other frameworks. Whether you need responsive design, SEO, speed optimisation or anything else in the world of digital then get in touch. If you would like to work with Nathan, simply drop him an email at [email protected]

It’s good to share