How To Stop Further Comments On Your WordPress Posts
Disabling comments when setting up a new WordPress site is easy but what about if you decide later that with a ton of posts already, that allowing comments is more trouble than it’s worth?
Perhaps you’d also like to reduce the burden of managing and responding to comments on old posts by closing comments automatically on a post after a certain amount of time? Or maybe that author is no longer writing for your website?
In this Weekend Project, we are going to look at simple plugins to allow you to prevent further comments on your WordPress posts.
The value of comments really depends on the type of site you have and most WordPress site owners probably don’t own sites with the size of audience that encourages the attention-seeking trolls.
But trolls aren’t the only reason for wanting to control comments. You might publish a site around emotive subjects (climate change, politics, religion) where commenters seemingly can’t help themselves; or perhaps it’s just more mundane a reason such as not having the time to manage comments across an ever expanding body of posts.
Or in a scenario that is pertinent to WPMU DEV, closing the comments on a post written by an author who no longer contributes to the blog.
Whilst disabling comments when setting up a new site is as easy as ticking a checkbox in Settings > Discussion, it’s a little trickier on existing sites, especially those with plenty of content.
Of course, there’s always the manual options but we’ve all got better things to do with our time, so let’s look at automated solutions for the two most common scenarios:
- Disabling new comments on existing posts, with the possible requirement of hiding existing comments
- Closing comments on posts after a certain amount of time
Disabling Comments On Existing Posts
The quickest method is to use the Automatically close comments on articles older than setting in Settings > Discussion. Setting this to 1 (0 doesn’t have any effect) will close the comments on all posts older than 1 day.
The biggest issue with this setting is that it only applies to posts and so pages and any custom post types will still continue to show the new comment form.
If you have pages or custom post types then you are going to need to add some custom code (see below).
Hear No Evil
This amusingly named and simple plugin has just two self-explanatory options: block comments and hide existing comments. The plugin will apply the settings to pages and custom post types, as well as posts making it a quick and easy method to effectively remove comments from your site.
WP Disable Comments
If Hear No Evil is the sledgehammer, then WP Disable Comments is the scalpel providing incredibly fine-grained control that allows you to disable comments (as well as pings, trackbacks and XML-RPC) for a range of posts, specific users, categories, tags, authors, post formats, post types, referrers, IP addresses, URL paths and even languages (requires qTranslate).
Closing Comments After A Specified Time On All Post Types
As we’ve already seen, closing comments after a certain number of days on posts is as simple as ticking a checkbox and entering the number of days in the Settings > Discussion panel.
The downside of this simplicity is that this only gets applied to posts, so pages and all your custom post types merrily continue on as before.
The remedy is to hook a small function to the close_comments filter to check whether the item’s comments should be closed:
There’s no changing of stored data, so installing or removing the code has no permanent impact on your site.
I’ve provided this as a plugin but as the approach will only work with a theme that uses the comments_open template tag, it would not be a serious crime against WordPress Coding Standards to add it to your theme’s (or preferably child theme’s) functions.php.
Drastic Options and Sensible Practices
Whether to include comments on your site is a complex decision that needs to be taken on a site-by-site basis but if you do decide to close comments permanently then the plugins mentioned here will help.
Far less drastic is closing comments after a certain number of days. This is a sensible practice that is applicable to a far wider range of sites (it’s certainly applicable to this site) and with a small piece of custom code backing up builtin functionality is easy to implement.