Join Morten Rand-Hendriksen for an in-depth discussion in this video What is comment spam?, part of WordPress Developer Tips: Deleting Spam Comments in the Database.
Before we dive into removing comment spam, it might be a good idea to take a look at what comment spam is and how you can recognize it. Comment spam are comments that are placed in your sites, that usually have lots of links pointing back to someplace where someone is earning money. You have links pointing back to them. They're really sneaky because most WordPress sites allow anyone to leave comments, and what the comment spam people or comment spam bots do is they try to inject comments that look like real comments, but in reality are just garbage with links back to something they want to advertise.
So on the site, I've installed a bunch of comment spam that I grabbed off existing WordPress sites on the web. And here you can see a variety of different types of comment spam. If I scroll down here, you see, these are the most typical ones. They're generally put together of random sentences. I think that this happens when scripts are just scouring the Internet and then they find random sentences and string them together. So you often get these very strange, long strung-on sentences that mean nothing. They are then posted with a name like Cheap Parajumpers.
And if you click on the link, you end up on some other site. Next one you see here is the same, only this one is in French, and it actually has lots of code in it, too. So, it's very clear that these two are spam. But there's another type of spam that I also see a lot, that I call spam bait. And it looks kind of like this. You have a comment that's really innocuous and very generic. Like this one. It says, I blog frequently and I really thank you for your content. This great article has truly piqued my interest. I'm going to bookmark your website and keep checking for new information about once per week.
I subscribe to your RSS feed too. Now this sounds like a generic comment from someone who read your site. But when people leave comments they generally don't leave super vague comments like this. So you're pretty much guaranteed that this is spam. Now you may wonder, why would someone want to leave comment like this? In some cases, it doesn't even have a link attached to it. Well, there's a good reason. If we go to the settings for your site, so I go to the Admin panel, and to Settings, and Discussion.
You'll see that by default, WordPress is set up down here so that it says, before a comment appears, comment author must have a previously approved comment. So the reason why someone would leave these very generic messages that almost sound real, but are a little too unspecific to be real comments, is they want you to get to approve them so they get past this barrier. So once you approve one of these generic comments, all of a sudden you'll get tons of spam comments onto your site. So it's a really good idea to try to spot these super generic comments and flag them as spam so that you don't open the floodgates to be spammed by the same person.
So now that you know what comment spam is, and what it looks like, it's time to look at how we can filter for comment spam, and also remove all of it from our site.