{"id":129793,"date":"2014-06-14T11:30:00","date_gmt":"2014-06-14T15:30:00","guid":{"rendered":"http:\/\/premium.wpmudev.org\/blog\/?p=129793"},"modified":"2014-06-13T01:36:08","modified_gmt":"2014-06-13T05:36:08","slug":"how-to-stop-comments-on-your-wordpress-posts","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/how-to-stop-comments-on-your-wordpress-posts\/","title":{"rendered":"How To Stop Further Comments On Your WordPress Posts"},"content":{"rendered":"<p>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&#8217;s worth?<\/p>\n<p>Perhaps you&#8217;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?<\/p>\n<p>In this Weekend Project, we are going to look at simple plugins to allow you to\u00a0prevent further comments on your WordPress posts.<\/p>\n<p><!--more--><\/p>\n<figure id=\"attachment_129994\" class=\"wp-caption aligncenter\" data-caption=\"true\"><a rel=\"lightbox[129793]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/pull-plug-comments.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-ratio-large wp-image-129994\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/pull-plug-comments-700x218.jpg\" alt=\"Weekend Project feature image\" width=\"700\" height=\"218\" \/><\/a><figcaption class=\"wp-caption-text\">There are number of options for preventing or restricting comments on your site<\/figcaption><\/figure>\n\n<p>Website comments have been a recent talking point with <a title=\"Read this article on The Atlantic website\" href=\"http:\/\/www.theatlantic.com\/technology\/archive\/2014\/06\/internet-comments-and-perceptions-of-quality\/371862\/\" rel=\"noopener\" target=\"_blank\">a recent article from\u00a0The Atlantic<\/a> prompting WP Tavern&#8217;s Sarah Gooding to post\u00a0a <a title=\"Read Sarah's article on WP Tavern\" href=\"http:\/\/wptavern.com\/why-comments-still-matter\" rel=\"noopener\" target=\"_blank\">spirited defence of comments<\/a>.<\/p>\n<p>The value of comments really depends on the type of site you have and most WordPress site owners probably\u00a0don&#8217;t own sites with the size of audience that encourages the attention-seeking trolls.<\/p>\n<p>But trolls aren&#8217;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&#8217;t help themselves; or perhaps it&#8217;s just more mundane a reason such as not having the time to manage comments across an ever expanding body of posts.<\/p>\n<p>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.<\/p>\n<p>Whilst disabling comments when setting up a new site is as easy as ticking a checkbox in <strong>Settings<\/strong> &gt; <strong>Discussion<\/strong>, it&#8217;s a little trickier on existing sites, especially those with plenty of content.<\/p>\n<p>Of course, there&#8217;s always the manual options but we&#8217;ve all got better things to do with our time, so let&#8217;s look at automated solutions for the two most common scenarios:<\/p>\n<ol>\n<li>Disabling new comments on existing posts, with the possible requirement of hiding existing comments<\/li>\n<li>Closing comments on posts after a certain amount of time<\/li>\n<\/ol>\n<h2>Disabling Comments On Existing Posts<\/h2>\n<p>The quickest method is to use the\u00a0Automatically close comments on articles older than setting in <strong>Settings<\/strong> &gt; <strong>Discussion<\/strong>. Setting this to <em>1<\/em> (0 doesn&#8217;t have any effect) will close the comments on all posts older than 1 day.<\/p>\n<figure id=\"attachment_129796\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"size-ratio-large wp-image-129796\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/Screen-Shot-2014-06-07-at-10.45.24-PM-700x93.png\" alt=\"Partial screenshot of the Discussion Settings\" width=\"700\" height=\"93\" \/><figcaption class=\"wp-caption-text\">A nice feature but only works on posts<\/figcaption><\/figure>\n<p>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.<\/p>\n<p>If you have pages or custom post types then you are going to need to\u00a0add some custom code (see below).<\/p>\n<h3>Hear No Evil<\/h3>\n<p>This amusingly named and\u00a0<a title=\"More about this plugin in the WordPress Repository\" href=\"https:\/\/wordpress.org\/plugins\/hear-no-evil\/\" rel=\"noopener\" target=\"_blank\">simple plugin<\/a> has just two self-explanatory options: block comments and hide existing comments. \u00a0The 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.<\/p>\n<figure id=\"attachment_129795\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-129795\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/Screen-Shot-2014-06-07-at-10.27.41-PM.png\" alt=\"Settings page for Hear No Evil plugin showing two options\" width=\"700\" height=\"208\" \/><figcaption class=\"wp-caption-text\">Very simple, very effective method for removing comments from your WordPress site<\/figcaption><\/figure>\n<h3>WP Disable Comments<\/h3>\n<p>If\u00a0Hear No Evil\u00a0is the\u00a0sledgehammer, then <a title=\"Read more about this plugin on the plugin repository\" href=\"http:\/\/wordpress.org\/plugins\/wp-disable-comments\/\" rel=\"noopener\" target=\"_blank\">WP Disable Comments<\/a> 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\u00a0users, categories, tags, authors, post formats, post types, referrers, IP addresses, URL paths and even languages (requires qTranslate).<\/p>\n<figure id=\"attachment_129797\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-129797\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/06\/Screen-Shot-2014-06-07-at-10.43.53-PM.png\" alt=\"Screenshot of the WP Disable Comments Settings page\" width=\"700\" height=\"1064\" \/><figcaption class=\"wp-caption-text\">This plugin allows for fine-grained control over when to disable comments<\/figcaption><\/figure>\n<h2>Closing Comments After A Specified Time On All Post Types<\/h2>\n<p>As we&#8217;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 &gt; Discussion panel.<\/p>\n<p>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.<\/p>\n<p>The remedy is to hook a small function to the close_comments filter to check whether the item&#8217;s comments should be closed:<\/p>\n<div class=\"gist\" data-gist=\"d15ee7ef196df5fe25f2\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/d15ee7ef196df5fe25f2.js\">Loading gist d15ee7ef196df5fe25f2<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>There&#8217;s no changing of stored data, so installing or removing the code has no permanent impact on your site.<\/p>\n<p>I&#8217;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\u00a0crime\u00a0against WordPress Coding Standards to add it to your theme&#8217;s (or preferably child theme&#8217;s) functions.php.<\/p>\n<h2>Drastic Options and Sensible Practices<\/h2>\n<p>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.<\/p>\n<p>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&#8217;s certainly applicable to this site) and with a small piece of custom code backing up builtin functionality is easy to implement.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this Weekend Project, we are going to look at simple plugins to allow you to prevent further comments on your WordPress posts either immediately or after a certain number of days.<\/p>\n","protected":false},"author":262394,"featured_media":129994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[9798],"tutorials_categories":[],"class_list":["post-129793","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-weekend-wordpress-projects"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/129793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/262394"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=129793"}],"version-history":[{"count":1,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/129793\/revisions"}],"predecessor-version":[{"id":215943,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/129793\/revisions\/215943"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/129994"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=129793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=129793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=129793"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=129793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}