Content MarketingSocial Media & Influencer Marketing

WordPress: Why I Removed Comments (And How I Removed Them)

I deleted all comments on Martech Zone today and disabled all comments in my child theme. Let’s discuss why it’s a smart move to remove and disable comments on your WordPress website:

  1. Spam Prevention: Comments on WordPress sites are notorious for attracting spam. These spam comments can clutter your website and harm your online reputation. Managing and filtering through these spam comments can be time-consuming and counterproductive. By disabling comments, you can eliminate this hassle.
  2. Images Not Found: As I crawled the site for issues, one that continued to crop up was commenters that had abandoned the use of Gravatar, WordPress’ means of displaying a commenter’s profile avatar or image. Instead of Gravatar gracefully displaying a standard image, it would instead produce a file not found, slowing the site and producing errors. In order to correct this, I’d have to troubleshoot the commenter and delete them… too time-consuming.
  3. Maintaining Link Quality: Allowing comments on your WordPress site can lead to the inclusion of external links within those comments. Some of these links may be from low-quality or spammy websites. Search engines consider the quality of outbound links when ranking your website. Disabling comments helps you maintain control over the links on your site and prevents potentially harmful links from affecting your rankings.
  4. Time Efficiency: Managing and moderating comments can significantly drain your time and resources. Time spent managing comments could be better utilized for other crucial tasks related to your sales and marketing efforts. Disabling comments frees up valuable time to focus on content creation, SEO optimization, and other sales and marketing activities.
  5. Shift to Social Media: In recent years, the landscape of online discussions has shifted away from website comments and more towards social media platforms. Users are more likely to share, comment, and engage with your content on social media sites like Facebook, Twitter, or LinkedIn. By directing the conversation to these platforms, you can tap into larger, more active communities and enhance your marketing efforts.

How to Delete Comments

Using MySQL and PHPMyAdmin, you can delete all current comments with the following SQL command:

TRUNCATE TABLE wp_commentmeta;
TRUNCATE TABLE wp_comments;

If your WordPress tables have a different prefix than wp_, you’ll need to modify the commands for that.

How to Remove Comments

This code in your WordPress theme or child theme’s functions.php file is a set of functions and filters designed to disable and remove various aspects of the comment system on your WordPress website:

// Disable comment feeds
function disable_comment_feeds(){
    // Add default posts and comments RSS feed links to head.
    add_theme_support( 'automatic-feed-links' );

    // disable comments feed
    add_filter( 'feed_links_show_comments_feed', '__return_false' ); 
}
add_action( 'after_setup_theme', 'disable_comment_feeds' );

// Disable comments on all 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('admin_init', 'disable_comments_post_types_support');

// Disable comments
function disable_comments_status() {
	return false;
}
add_filter('comments_open', 'disable_comments_status', 10, 2);
add_filter('pings_open', 'disable_comments_status', 10, 2);

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

// Disable comments menu in admin
function disable_comments_admin_menu() {
	remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'disable_comments_admin_menu');

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

Let’s break down each part:

  1. disable_comment_feeds: This function disables comment feeds. It first adds support for automatic feed links in your theme. Then, it uses the feed_links_show_comments_feed filter to return false, effectively disabling the comments feed.
  2. disable_comments_post_types_support: This function iterates through all the post types in your WordPress installation. For each post type that supports comments (post_type_supports($post_type, 'comments')), it removes support for comments and trackbacks. This effectively disables comments for all post types.
  3. disable_comments_status: These functions filter the status of comments and pings on the front-end to return false, effectively closing comments and pings for all posts.
  4. disable_comments_hide_existing_comments: This function hides existing comments by returning an empty array when the comments_array filter is applied. This ensures that existing comments won’t be displayed on your website.
  5. disable_comments_admin_menu: This function removes the “Comments” page from the WordPress admin menu. Users with the necessary permissions will no longer see the option to manage comments.
  6. disable_comments_admin_menu_redirect: If a user tries to access the comments page directly by navigating to ‘edit-comments.php,’ this function redirects them to the WordPress admin dashboard using wp_redirect(admin_url());.

This code completely disables the comment system on your WordPress website. It not only disables comments for all post types but also hides existing comments, removes the comments page from the admin menu, and redirects users away from the comments page. This can be helpful in situations where you don’t want to use the comment functionality and want to simplify your WordPress site’s backend.

Douglas Karr

Douglas Karr is CMO of OpenINSIGHTS and the founder of the Martech Zone. Douglas has helped dozens of successful MarTech startups, has assisted in the due diligence of over $5 bil in Martech acquisitions and investments, and continues to assist companies in implementing and automating their sales and marketing strategies. Douglas is an internationally recognized digital transformation and MarTech expert and speaker. Douglas is also a published author of a Dummie's guide and a business leadership book.

Related Articles

Back to top button