Monday, August 20, 2007

Reduce Comment Spam on Blogger with a Simple Javascript Trick

Dealing with comment spam is probably the biggest headache for most bloggers - the comment will have a word like "Cool" or "Interesting" and then a URL pointing to some online pharmacy story selling prescription drugs.

While WordPress has the excellent Akismet anti-spam filter that catches majority of comment spam, Google provides simple word CAPTCHAs and email based comment moderation for Blogger blogs. They also add a rel=nofollow for all links left in the visitor comments section and therefore deny any Google Juice to the linked website.

blog comment spam statistics

Even with these spam prevention measures in place, the problem is far from over. So how do you reduce the menace ? Just turn off comments, not for the entire blog but just for old blog posts.

Why ? Well, if you look at pending comments in your moderation queue that require approval, you'll see a pattern - the blog posts that are more popular in search engines are the biggest target of comment spam.

Blog comment spammers rarely target fresh posts that you have recently published because spammers discover their targets (your blog posts) via search engines and fresh posts are less likely to rank high in search results.

Now how do you disable comments in Blogger for old posts because unlike WordPress, there are now AutoShutOff and Comment Timeout plugins for blogger? The answer is simple - use Javascript.

<script type="text/javascript" language="javascript1.2">
var shutoffperiod = "2" // Turn Off Period (in months)
var str = "<$BlogItemPermalinkURL$>";

var year = str.split("/")[3];
var month = str.split("/")[4];
var d = new Date();


var diff = (d.getFullYear() - year)*12 + d.getMonth() + 1 - month;


if (diff <= shutoffperiod) {
document.write('<a href="http://www.blogger.com/comment.g?');
document.write('blogID=1234&postID=<$BlogItemNumber$>">Comment</a>');
} // Replace 1234 with your Blog ID 
</script>


All you have to do is replace your Post a Comment blog in the blogger template with the above code. It computes the date of the blog post from the permalink and depending on the age of the blog post, the "Post a Comment" link will be added to your blog post.


Remember to replace 1234 with your Blog ID. The comment posting link for visitors is hidden by default for blog posts that older than 2 months. You can modify the default setting by changing the value of shutoffperiod variable in the script.


Related: Add Visitor Comments Policy in Blogger

0 comments:

Post a Comment