Hi guys. Now I quickly put you on the shelves a few instructions on how to disable comments in WordPress.
Given that WordPress ( how to install WordPress) is a blog engine, comments are one of the main functions and therefore included by default. Well, this is not an obstacle!
After all, it happens so that comments are either not needed at all (maybe you are attacked by spammers or you just do not want to communicate with commentators), or you need to disable them to some pages (either for a day or forever if the article is advertising). Or maybe you are doing just a satellite or a GE and do not want to follow the comments in advance?
What to do? About this and we will talk today – for you necessarily there will be a suitable variant.
How to disable the addition of new comments in WordPress
Go to “Admin Dashboard” -> “Settings” and finally “Discussion”. Now, while in the “Discussion Settings” menu, uncheck the box “Permit to leave comments on new articles”. Let me show you the screenshots:
The problem with this method is that the restriction will only apply to comments on new articles – under them, there will be an inscription “No comments” or “Comments disabled”. If this is enough for your tasks, then we can stop at this. If you want to turn off already published comments to old articles – go to the next item.
How to remove comments from the site to all posts in WordPress
Go to index.php, delete in it:
<? php comments_popup_link ( '? No Comments' , '? 1 Comment' , '? % Comments' ) ; ?>
What will happen? On your blog, the message “Comments disabled” will be disabled.
Then, go to the archive.php file and delete:
<? php comments_popup_link ( 'No Comments' , ' 1 Comment' , ' % Comments' ) ; ?>
After that, edit the single.php file – find there and delete the following code:
<? php comments_template ( ) ; ?>
This line is responsible for displaying comments on the blog because it disables not only the form itself for users to add messages but also the call of all comments from the site’s database. Old comments will remain in the database, and we’ll talk about cleaning up the database.
Note: topics are written by different developers, so the code can vary slightly, but the overall form remains approximately the same.
Note 2: The above method has a problem. If your theme is updated and you want to install a new version, the changes you have to make will have to be done anew. So think, edit the code again, or do not update the topic. Or use plugins!
What are the plugins for disabling comments on WordPress?
If you are too lazy to pick the code and you just want to click the button and that everything works, you will need plug-ins to disable comments.
Reduce the use of plugins. Use only when you can’t add it via code since they do not always work well with non-standard themes, the developers of which depart from the rules of WordPress themes development.
But there is a plus point of using a plugin is you do not need to worry about the need to regularly fix the code in your topic if it is often updated.
I will not give a link to all the plugins that perform this function (No Page Comment, Hide Comments Feature, and Disable Comments On Pages) because they had problems with working capacity. But the Disable Comments plugin did not have such problems and I can safely recommend it.
The plug-in for disabling comments in WordPress Disable Comments has the following settings (disabling all comments, or banning commenting on certain types of pages):
Disable comments from certain pages and records on the site
Instructions for disabling comments on pages:
Go to the “Records” tab in the WordPress console and select the desired entry. Now click on “Properties” or “Quick Editing” (depending on the version of WordPress) and uncheck the last item “Allow commenting”.
Do not forget to click Update or Update!
You can do this and not from the main menu, but at the time of writing the article. To do this, find the “Discussion” block and turn off the comments there:
If you can not find this block, it’s okay, it can be hidden in the display settings of the blocks ie. in the “Screen settings” menu on the top.
The instruction for disabling comments in the records is similar (only you need to go to the “Pages” tab).
Turn off comments for a specific category (category)
Where it can come in handy? Well, let’s say I have a cool, high-profile blog (if not, then we’ll teach you how to create a blog for free) and under the heading “Advertising” I place advertisements for questionable means for losing weight and do not want users to leave comments (anything can happen).
Then we need to disable comments in a certain category – all entries in this section will be published without commenting, and comments on old entries will be lost.
Find the file single.php, it should already have a line familiar to us:
<? php comments_template ( ) ; ?>
You need to replace the following code:
<? php if ( in_category ( 'x' ) ) : ?> <? php else : ?> <? php comments_template ( ) ; ?> <? php endif ; ?>
X – Category ID. Find this ID is very simple, go to “Categories” and click “Edit” any category. In the address bar you will have something like:
This figure is the ID. If you need to prevent comments on several categories, then simply list them through commas.
Finally, we’ll work with comments in the WordPress database using PHPMyAdmin.
How to disable WordPress comments via phpMyAdmin?
To work with the database resorted usually in the case if you need to save time and nerves, not running through the pages and not turning off the tick. Well, in fact, suddenly we have 15,000 records, 100 categories, and a thousand pages – this information in the database, after all, is reflected in the work of the site.
So, go to the SQL tab in the database of your site. A window of requests appears before your eyes. We enter the following requests there.
In order to turn off the ability to comment on ALL articles:
UPDATE wp_posts SET comment_status = 'close' ;
Cancel, return back, do as it was:
UPDATE wp_posts SET comment_status = 'open' ;
Leave the possibility of commenting only for those lucky ones who registered on your blog:
UPDATE wp_posts SET comment_status = 'registered_only' ;
Select the required query and click OK. Have driven on, but let’s delete all the comments in our blog.
How to delete all WordPress comments via phpMyAdmin?
An example of a SQL query to delete all comments will delete all Unapproved comments (for example, thousands of accumulated spam):
DELETE FROM wp_comments WHERE comment_approved = '0' ;
The SQL query will remove all approved comments:
DELETE FROM wp_comments WHERE comment_approved = '1' ;
We press “Ok”, we go to drink tea in jam.
I hope this article helped you to disable comments in WordPress, and if it did not help (it would be strange, how much more) I’m waiting for your questions in the comments.