Search Form

Wordpress Minimum Comment Content Length – Fighting Comment Spam

  • 73 Comments

Between showing the top commentators on the sidebar and the contest to win a MacBook Air I have had a lot of experience with fighting comment spam. Also from being a moderator at one of the busiest forums on the internet I have seen many methods people use to jackup their post counts. Many times people just post "I agree" or "please pm me" and I find it extremely annoying.

Forcing people to post longer comments will not help you much with automated spam (I will have tips on that in another post) but it will help you a ton with human spam. The true human spammers who were going to just type "yes" will now type "asdf asdf asdf asdf yes" and now their intent to spam is identified and they can be banned properly. The people who did not intend to spam will simply add a bit more content to their sentence. Thats the hope anyway.

So how to do it? Well I started to poke around the Wordpress files looking for something that made sense and I on line 89 of the wp-comments-post.php file I found this:

PHP:
  1. if ( '' == $comment_content )
  2.         wp_die( __('Error: please type a comment.') );

Aha! That makes sense. Basically that is saying if the comment is empty then invoke the wp_die function and say "Error:please type a comment".

While their is no documentation on the Wordpress function reference for "wp_die", just by trying a comment with no content you can conclude pretty much that wp_die means show a custom page with the message we are passing and then stop.

So I added this right after that:

PHP:
  1. if (strlen($comment_content) <25 )
  2.    wp_die( __('Error: Your Comment Is Too Short. Please try to say something useful.') );

What does this do? strlen is a php function that gets the "string length" then it checks to see if it is less than 25 chars. If it is it sends them to the custom wp_die page with the error message of Error: Your Comment Is Too Short. Please try to say something useful.

Now hacking on your Wordpress files to accomplish a goal is pretty cool and educational BUT the next time you upgrade your Wordpress your changes are going to go bye bye...

The long term way is to build a plugin. Which I asked Joost if he could do it and gave him my code. A couple minutes later he had it done. Here it is for you to download.



Please read this disclaimer before acting on this post.
  • 73 comments. What say you?
    • RSS

Comments

  1. TechNald

    great work sir! god bless!

  2. Nicholas Chase

    Jeremy, Excellent! I have just created a blog to learn WordPress, and am using my reviewing products from ClickBank promotions, with the link embedded in the body text of the post. You have a great friend there in Mr. Joost.
    Respectfully, Nicholas [The Guitar Blog] http://nachase.wordpress.com/

  3. twig

    I could implement it on my actual posts to ensure they’re long enough too :)

  4. Jeff Finch

    Thanks for letting me know about this ;)

  5. Mario

    it should be great if we have this code in javascript comment checker also

  6. terminator69

    Good post, id like to see if this actually helps with spam or not.

  7. Omar

    hahaha good alternative but
    this really work ? :)

    look leshii post hahaha

  8. Jef

    I posted on another story and my comment never showed up. It was rather long. If you can’t read this, it means that this one didn’t show up either.

  9. ShoeMoney

    sure that would be pretty easy ;) Just instead of wp_die do a:

    header(”Location: http://www.example.com/“);

  10. leshii

    Thank’s thas’s im looking for

  11. Blue SEO

    Yeah, I agree, you should rickroll him hahaha. Yeah it’s a good thing to have the spam check in place on a Wordpress blog with all of the comment spammers out there.

  12. Dick

    I agree, this is a very useful thing. Spam is growing exponentially proportions in recent times. Thank you, Shoe.

  13. Mubin

    Is there anyway that you could redirect this haphazard spammer to a youtube video of rick astley?

  14. Instant Community

    Yeah thanks for the tips and sharing this lovely piece of code. Fighting Spam is one of the biggest challenges now actually!

  15. Sire

    Well blow me down and call me a dumb Aussie Blogger. Isn’t it amazing how something so small can make such a big difference. I reckon I will give this plugin a go. Thanks for the tip, oh and it goes without saying ‘nice blog’ ;)

  16. Agent Magenta

    Fighting comment spam is a bit like the cold war – for every advance made the spammers up the ante by finding ways around. Its going to be a long time before human moderation can be replaced but nice plugins like this will help reduce the workload by stopping the majority of the spam.

  17. Zak Show

    aha, lol! very good way to keep spammers away. Thanks j for sharing this. I hope that my comment is Ok :P

  18. Rajaie AlKorani

    I always enjoy snooping around the WordPress files, that’s how I found out how to remove the update nag that shows when a new WordPress version is available.

  19. ajaz

    Cool plug-in to fight a growing issue. I will be adding it to my blogs, it should save a bit of time.

  20. Miguel Verissimo

    Great tip, thanks for sharing and for making it into a plugin. I wonder why simple stuff like that is left out by the wordpress team…

  21. Miguel Verissimo

    I love little hacks like this, thanks for sharing. Wordpress is such a powerfully supported tool, it’s hard to me to understand why simple things like this is left out.

  22. Erica DeWolf

    Great tip- thanks so much for sharing!!!

  23. Ultimate Blogging Experiment

    People that spam others are just Internet stupid. The backlash against these people is getting so big that as soon they will be getting caught faster and faster and going to jail for years. People need to think about the consequences. Only problem is a lot of people don’t care.

  24. Vacation Rentals

    Great idea, I have been getting bombarded by manual comment spammers as of late so it probably won’t help to much since most of them are already writing longer comments.

  25. Melvin

    i thought you dont moderate comments here in your blog… well dp is really a hard task.. well i think they have somehoiw changed their policy there…

  26. TYCP Entertainment Magazine

    I like the way you think. I was thinking “Okay, this is great, but the next upgrade will override these settings”, but voila – you put a link to the plugin version. I’m implementing this right away. I hate when people leave comments like that, if you even call them REAL comments.

  27. Winning Startups

    My site doesnt have nearly the comments yours does I guess its a good and bad thing to have so many people placing comments on your site. I wish there were more “plugins” for blogger sites, or I wish it were easier to change from blogger to wordpress, seems all the good advice is for wordpress blogs.

  28. Talk Binary

    After reading this post I came across an unmoderated comment that said VERY NICE!

    I then realized the link they had was to some bad naughty pictures. XD

    This plugin doesn’t come at a bad time at all!

  29. Justin Cook

    I was one paragraph away from finishing the read, and I thought “man, I should just whip together a plugin for this, let you set the min. comment length”.

    And then your last paragraph deflated me.

  30. Webmaster Forums

    Although it an attempt to fight the spam comments, I doubt if it would be much effective. Spammers would come up with new ways. I am kind of surprised though wordpress does not check comment length!

  31. Dogs

    nothing frustrates us more than battling spam!!!
    Never ending circus!

  32. Monchster

    Genius! I have never though about a plug-in for just that. I have noticed a lot of spammers including jibberish in their commens with tons of links. Can the code also include a max set of chars.?

  33. entrenewbie

    Thanks for the tip along with some great insight on a lot of the real “motivation” to leave a comment on someone’s blog…. leave a comment because you want to participate, not because you want to be recognized!

    thanks again for helping to fight the good fight with this tip.

  34. cheap used cars

    sure, but sometimes less is more.

  35. TEKFIRM

    any ban plugin to be released soon ? :P

  36. ShoeMoney

    and just like that your banned see how easy it is to spot the spammers ;)

  37. TEKFIRM

    Aksimet wont catch human spam , this plugin is for humans and not bot :)

    most bot spam are like 1000words+

  38. meethere

    Now thats something interesting..
    Thanks joost and shoe.

  39. newmediaMike

    Thanks for the tip!

    I only wish I was having this problem so I could implement this hack. Akismet intercepts my spam for me and I have yet to have a short winded poster comment on any of my posts.

    Not that I am calling my readers blowhards! I love my long winded intelligent readers.

  40. Start Blogging

    That’s really smart! I’m not too good with PHP coding, and Aksimet doesn’t always catch spam, so this is perfect.

  41. TEKFIRM

    he should have mentioned you at least in the contributors !

  42. Architecture

    Error: Your Comment Is Too Short. Please try to say something useful.

  43. Andrew

    going to try it…I already have some plugins from Joost’s website running on my blogs. I recommend to anyone that runs WP to use Meta Robots from Joost (much more complete than All in One Seo plugin)

  44. VaBeachKevin

    yeah i was just adding a bunch of spaces between the words. a simple check for that and you should be good to go.

  45. Patrick

    I was wondering when you were going to implement this. But yeah, I think it is counting spaces.

  46. wesley

    Yeah, just add a trim() before you do the strlen() check :)

  47. ShoeMoney

    ahh lamer your using a ton of whitespace =P ill do a check for that too

  48. Geiger

    That’s a good idea! (blank) ;)

  49. VaBeachKevin

    2nd try

  50. Bryn (Internet Is My Life)

    Awesome, I was about to go add the line of code when I kept rerading and saw the plugin! Oh how wonderful…installing now, thanks Jeremy and Joost.

  51. ShoeMoney

    hmm it should be working try again

  52. VaBeachKevin

    hmmm doesn’t work too well (if you are using it).

  53. River Girl

    I received this from Joost in his email blast on Saturday. Very cool indeed.

  54. devtrench

    Does it piss you off when people keyword stuff the Name they use when they comment? This didn’t used to annoy me but I’m getting tired of ‘Coral Snake’ and ‘portland oregon web design’ commenting on my blog. My new comment policy is to change the name of the commenter slightly so they can’t get on the top commentators list and stay in no-follow hell.

  55. John Cow

    It makes me laugh at how things like this often start at us right in the face and we just move along living with it. Thanks for putting a little thought into this… I have downloaded and installed :)

  56. Lawrence

    I agree – comment spam is annoying…much more so, if the comment is not intellectually-stimulating…are you feeling me?

  57. team ray

    joost the php master

    good tips shoemoney

  58. filontheroad

    Great Tool !!! Thank you for that idea and big thanks to Joost too for making that so quick.

  59. Hustle Strategy

    I was tripped up by this here to other day. I added more content to the post. It is neat and should serve the purpose that you intend. The biggest problem with customizing wordpress is the upgrades, but being able to make the plugins is a plus.

  60. Sohan

    I would implement it if I had a lot of comments :P I get about 2-3 a week tops.

  61. Wcnktm

    Very Useful Plugin. Thank you verymuch for sharing it.

  62. Chris Abernethy

    This is a pretty cool plugin, I was checking it out on Joost’s site the other day. It sounds like it will be really helpful for sites like this one where there are comment contests etc., as well as dofollow blogs that don’t want to get filled with ‘mee too’ spam.

  63. narendra.s.v

    wow thats what i have thought today as i have some 69000+ comments so far by Akismet but since from the past few days am getting small size comments like “is this is great”, “interesting one” all that links to spam, now i gonno try this out :D

  64. BlackhatWay

    Hey, thanks for the tip! I haven’t had a problem like this in my blogs yet, but if I start to see posts like that, I will try this!

Trackbacks url:

By commenting on this post you agree to the comment policy

Leave a Comment...