How Comment Spam Bots Work?
Blogger (service) is a used by millions of blogs and websites. Therefore, all these websites uses the same Blogger commenting system unless they are using a third-party commenting system. This means, it makes it a lot easier for spam bots to find blogs and post spam comments.
Some spam bots are smart enough to fill captcha and flexible enough to answer different questions to fool the website's spam prevention system. This means, the best way to tackle spam bots is to completely block them from commenting on your website.
Method#1: Blocking Spam Bots in Blogger Using b:if Condition
In the first method, we will block bots using b: if condition. Therefore, to ban a user from commenting on your site, you have to find his Blogger Profile URL and using b: if condition stop him from accessing comment form. This will blacklist a specific user's Blogger profile and he will no longer be able to make or see any comments on your site.
- To find a user's Blogger Profile URL, go to your comment section and left click on the names of the comment posters.
- Now list of options will be appear, from the list select "Copy link address" as it is shown in the screenshot below:
- After copying the profile URL, go to Blogger >> Template >> Edit HTML >> Search for </body> and just below it paste the following code:
- Now in the above code, replace https://www.blogger.com/profile/XXXXXXXXXX with the Blogger profile URL you copied earlier. Keep in mind this will ban only one user to ban more users you have to paste the above code again in your template but with different profile URL.
- Once everything is done, save the template. Take a look at the screenshot below to the results:
<b:if cond='data:comment.authorUrl!= "https://www.blogger.com/profile/XXXXXXXXXX"' >
<script>
$(".comment-form").replaceWith("<p style=" color: #111; text-align: center; border: 1px solid #d2d2d2; padding: 13px; font-size: 15px; ">You are Banned from Commenting on this site</p>");
</script>
</b:if>
Method#2: Blocking Spam bots in Blogger with jQuery:
In the second method, we will block bots using jQuery.
- Go to Blogger >> Template >> Edit HTML >> search for the ending </body> tag and right above it paste the following jQuery code:
- Now in the above code, replace https://www.blogger.com/profile/XXX with the Blogger profile URL that you would like to ban. You can ban unlimited users by adding profile links in the above codes.
-
Once everything is done, press "Save Template". Take a look at the screenshot below to the results:
<script type='text/javascript'>
//<![CDATA[
//Block Spam Comment Bots in Blogger
//Black List Blogger Profiles
var spamlist = [
'https://www.blogger.com/profile/XXX', //First Ban User
'https://www.blogger.com/profile/XXX', //Second Ban User
'https://www.blogger.com/profile/XXX' //Third Ban User
];
for (var v = 0; v < spamlist.length; v = v + 1) {
$("a[href='" + spamlist[v] + "']").each(function() {
$(this).closest(".comment-block").find(".comment-actions, .datetime, .comment-replybox-thread, .comment-block")
.replaceWith("");
$(this).closest(".comment-block").find(".comment-content")
.replaceWith("<div class='comment-content' style='color:red'>This user's comment has been removed!</div>");
$(this).replaceWith("<span style='color:red'>BANNED USER!</span>");
})
}
//]]>
</script>
About the Editorial Team
The Editorial Team of MyBloggerLab consists of a group of Professional Blogger geeks Led by Syed Faizan Ali (Founder of MyBloggerLab).
2 comments
Hello, congratulations for this tutorial. I was waiting a long time how to block spam in blog comments system. It´s works fine on my blog!
The only issue is that this script works only for the web template, but do not works for de mobile template blogger.
So, if you use a smartphone to acess your blog, spam comments from baned users is still there.
It would be nice if could work to mobile template too.
Thanks in advance.
Woow Awesome post. This is really helpfull for me. You made my day. I just loved this article. You helped me alot so I just wanna say thanks to you.
Thank you.
Post a Comment
We’re eager to see your comment. However, Please Keep in mind that all comments are moderated manually by our human reviewers according to our comment policy, and all the links are nofollow. Using Keywords in the name field area is forbidden. Let’s enjoy a personal and evocative conversation.