By default, all posts and pages in WordPress allow users to post comments. While some websites will find this feature useful, in most cases comment forms only attract spam bots. Spam is the primary reason to disable comments in WordPress. To block comments, developers can customize Discussion settings, edit the template files or use a disable comments plugin.
Disabling WordPress comments using Discussion settings
Discussion settings allow developers to customize Worpress comments in many ways. This settings disable comments only on new articles. They do not affect previously published posts, so comment forms will still be present on older articles. To disable comments on all future articles folow this easy steps:
- in your WP dashboard, click on Settings and then Discussion
- Uncheck the checkbox named Allow people to post comments on new articles
- Additionally, mark the checkbox named Users must be registered and logged in to comment , to prevent spam bots to leave comments on older articles
- Save the changes
Disable Comments plugin for WordPress
The simplest way to disable comments in WordPress is to use a dedicated plugin. There are a couple of disable comments plugins in the WP Repository for this purpouse. Most used and best rated is Disable comments plugin by Samir Shah. The plugin has over a million active installations, over 200 five star ratings and it’s frequently updated. This super-light plugin doesn’t create additional server requests, so it won’t affect web site loading speed.
After installing and activating the plugin, all you have to do is decide to disable comments completely or partly. To customize this settings click on Settings in your WP Dashboard left column menu. Now click Disable comments in the Settings submenu. You can choose to completely disable comments everywhere, or block comments separately for pages, posts or media files. Save your preferences and get rid of annoying spam bot comments forever.
Note: When Disable Comments plugin is active, Discussion settings are disabled and you won’t be able to override comment blocking on single posts. Assumably, you won’t need those settings anyway.
Delete all comments in WordPress using the Disable Comments plugin
WordPress web sites are often released live on the web with comments enabled or not configured properly. Those sites will attire spam bots that will leave hundreds or thousands spam comments. It can take a very long time to delete those those comments page per page. Luckily, there are WP plugins that will delete all those junk comments with a single click.
We suggest to use the Disable Comments plugin, described above. The plugin will add a Delete Comments option to the WP Dashboard left column menu. You will find the Delete Comments option inside the Tools menu tab.
Important: Use this option only if you want to permanently delete all comments from your website. There is no option to selectively delete comments.
Block spam comments by editing template files
Some developers struggle to use as less plugins as possible to build web sites. In this case comments can be disabled by editing PHP template files. Good knowledge of HTML and basic understanding of PHP is required for this approach to blocking comments.
Pro Tip:It is highly advisable to work on child themes when editing template files. Otherwise you could loose all your customization when updating the WP theme.
How to remove comment forms from template files
Disabling WordPress comments by editing template files is done by locating and removing the code snippet that renders the comment forms. There are slight variations in the location and the format of the snippet in different themes. With basic understanding of PHP it’s not a problem to locate and remove the code from any theme. If yo’re not 100% sure what you are doing, firstly backup the template file you are about to edit. In case something goes wrong, you can easily revert to the original file.
Let’s take for example two most commonly used themes lately, WordPress defaut Twenty Seventeen and Twenty Nineteen.
Disabling comments in Twenty Seventeen WordPress Theme
To disable post comments in Twenty Seventeen, open the theme editor and locate the single.php template file. Now find the if … endif statement that calls the comments form located near the bottom of the file. Delete the statement carefully and save the changes.
To block comments on pages apply the same procedure to the page.php template file.
Disabling comments in Twenty Nineteen WordPress Theme
The procedure to disable comments in Twenty Nineteen WordPress theme is similar to the process described above. The only difference is a slightly different code snippet that calls the comments form. Locate the if statement near the bottom of the single.php template file. Delete it carefuly and save changes. Furthermore, repeat this process for the page.php template file to disable comments on pages.
PRO Tip: Editing WordPress template files is easier with colored and higlighted code. If your theme editor doesn’t already use syntax highlighting, we suggest you enable this feature. To learn how to enable syntax highlighting in Wodrpress read this article: How to highlight code in WordPress editor