Boost Your WordPress Site's Performance: Eliminate Comment Spam and Improve Speed with This One-Command Solution!
- The first step
- Disable Comments and Pings
- Delete Comments
- Disable Comments Site-wide
This article covers what to do when your WordPress installation gets attacked by spammers and they manage to add a large amount of comments which makes it impossible to manually delete. I speak from personal experience, having had to delete 500,000 (half a million) comments. The existence of
wp-cli has proven invaluable in this process.
The first step
Read the post related to this, about How to clean your WordPress site when it gets hacked which will explain how to install and setup
Disable Comments and Pings
Disable Comments on All Posts
This is the first step you should take. This way we stop new comments from spamming your posts.
wp post list --format=ids | xargs wp post update --comment_status=closed
Disable All Pings
As pings can be misused by spammers we want to disable them.
wp post list --format=ids | xargs wp post update --ping_status=closed
Exercise caution when utilizing some of these commands, as it has the potential to result in the loss of all your comments.
Delete Comments marked as SPAM
Filtering is activated in the following command, guaranteeing that only comments marked as spam will be deleted.
wp comment delete $(wp comment list --status=spam --format=ids)
Delete all Comments
Beware this command will delete all comments.
wp comment delete $(wp comment list --format=ids)
THE NUCLEAR DELETE OPTION
If you find yourself dealing with an extensive number of comments that would be time-consuming to delete individually, the only viable option is to perform the deletion at the database level. Execute the following
SQL query on your database to achieve this.
Tip: You need to connect to your database to perform SQL queries using any MySQL client.
Disable Comments Site-wide
The following example illustrates how to deactivate the comments feature within WordPress.
wp plugin install disable-comments --activate
wp disable-comments settings --types=all
In conclusion, managing and combating spam on WordPress sites is important for maintaining a clean, user-friendly, and SEO-friendly site. The strategies discussed in this article provide a complete approach to fighting the menace of spam comments, ensuring that the integrity of your website remains intact. By implementing a combination of comment disable type of plugin and comment setup and moderation with
wp-cli, site administrators can significantly reduce unwanted comments and in case it does happen they can quickly and effectively delete spam comments.