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:
- 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.
- 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.
- 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.
- 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.
- 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:
disable_comment_feeds
: This function disables comment feeds. It first adds support for automatic feed links in your theme. Then, it uses thefeed_links_show_comments_feed
filter to returnfalse
, effectively disabling the comments feed.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.disable_comments_status
: These functions filter the status of comments and pings on the front-end to returnfalse
, effectively closing comments and pings for all posts.disable_comments_hide_existing_comments
: This function hides existing comments by returning an empty array when thecomments_array
filter is applied. This ensures that existing comments won’t be displayed on your website.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.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 usingwp_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.