Prevent Spam Comments in WordPress

Posted on 25th July, 2013 Leave a Comment

This is a very popular subject indeed and to be honest I’m not surprised. For the most this is one of those things that you just have to put up with if you have an online presence. But thankfully there are a few things that you can do to make it near impossible for these spam whores from raping your comments.

So the first thing we can do is open up the .htaccess file in your main WordPress server folder, using an ftp client or your cpanel. Open it up in notepad or any text editor (NOT MS WORD!).


Block the Robots…

Add the following few lines at the bottom of our file.

### Deny Spambots ###
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} .wp-comments-post.php*
RewriteCond %{HTTP_REFERER} !.** [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) http://%{REMOTE_ADDR}/$ [R=301,L]

All this does is check to see if the comment comes from a human or a spam bot (if the comment has a referrer). If it’s from a spam bot then the comment gets blocked automatically.


Block the humans

This ones even simpler to solve than the robots; You have a few options here, using particular plugins and online services like akimet, but personally I prefer the free option. I’ve been using this plugin for about 3 years now and can count the amount of spam I’ve had come through on one hand.

Invisible capture

Believe me when i say that this is all you’re going to need.

Honestly this should come built in as a part of WordPress, there is no capture code to fill in, it does all the work in the background like a sneaky spam ninja.

LionScripts: IP Blocker Lite

ip blocker

This little baby will allow you to block persistent spammers by allowing you to add and block their IP address. But from personal experience spammers will change their own IP or use a dynamic IP witch will bypass this blocker, so this one is up to you.

Leave a Comment

To preserve code added to a comment you can wrap your code in short tags
by using [square brackets]:

  1. PHP use - [php] <?php code here ?> [/php]
  2. CSS use - [css] #code-here {} [/css]
  3. HTML use - [html] <div> code here </div> [/html]
  4. JS use - [js] $(".codeHere") [/js]