WordPress Plugin to Block Spam Comments

I don’t receive many real comments from actual humans on my posts, but I do receive a lot of annoying spam comments each day. It’s a nuisance to regularly empty the spam folder, but I prefer to leave the option to post comments open for the rare occasion when someone has a follow-up question or comment. There are many WordPress plugins available to block spam, however, they are typically overkill for a small site like mine. I wrote this plugin to provide a simpler solution to block the majority of spam comments. It is not meant to block every possible method that spammers have for generating comments, but it will block the vast majority. The intent was also to avoid employing user obstacles such as CAPTCHAs and other challenge-response tests.

I’ve had this plugin running on my site for several months and I have not had any spam comments.

Add the below code to a .php file and upload it to your plugin directory. Once uploaded, activate the plugin from your dashboard and it will begin blocking spam comments for your site.

The plugin uses three methods to filter spam comments:

  • Timestamp Method: If a comment is submitted in less than 15 seconds after viewing the page or after more than an hour, then the comment will be rejected as spam. The time thresholds should be adjusted to meet your individual needs. I’ve noticed that most spam comments are submitted within 5 seconds after viewing the page.
  • Honeypot Method: Many automated tools for generating spam comments will blindly add data to every available field in a form. The honeypot method adds a non-visible field to the comment form that will cause a comment to be rejected as spam if any information is submitted in the field.
  • Link Counter Method: If a comment includes 2 or more URLs in the comment body, then the comment will be rejected as spam. The number of allowed URLs in a comment should be adjusted to meet your individual needs. Spam comments generally have multiple URLs included in the comment body.

Leave a Comment