Ned Hello, I'm Nedim, a Cloud Engineer who enjoys writing about technology, particularly focusing on Linux and DevOps. Recently, I've been delving into topics like digital marketing, online presence, and startup culture.

Boost Your WordPress Site's Performance: Eliminate Comment Spam and Improve Speed with This One-Command Solution!

Boost Your WordPress Site's Performance: Eliminate Comment Spam and Improve Speed with This One-Command Solution!

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 wp-cli.

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

Delete Comments

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 all comments from WordPress database using SQL

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.

TRUNCATE `wp_commentmeta`; TRUNCATE `wp_comments`;

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.