Aug 4 2008
ShoeMoney

Wordpress Minimum Comment Content Length - Fighting Comment Spam

By ShoeMoney 72 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 Rate This Post: 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
  1. FF0000
    BlackhatWay said on August 4th, 2008 at 10:19 am

    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!

    [Reply]

  2. FF0000
    narendra.s.v said on August 4th, 2008 at 10:24 am

    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

    [Reply]

  3. FF0000
    Chris Abernethy said on August 4th, 2008 at 10:27 am

    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.

    [Reply]

  4. FF0000
    Wcnktm said on August 4th, 2008 at 10:34 am

    Very Useful Plugin. Thank you verymuch for sharing it.

    [Reply]

  5. FF0000
    Sohan said on August 4th, 2008 at 10:40 am

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

    [Reply]

  6. FF0000
    Hustle Strategy said on August 4th, 2008 at 10:47 am

    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.

    [Reply]

  7. FF0000
    filontheroad said on August 4th, 2008 at 10:49 am

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

    [Reply]

  8. FF0000
    team ray said on August 4th, 2008 at 10:51 am

    joost the php master

    good tips shoemoney

    [Reply]

  9. FF0000
    Lawrence said on August 4th, 2008 at 10:57 am

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

    [Reply]

  10. FF0000
    John Cow said on August 4th, 2008 at 10:58 am

    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 :)

    [Reply]

  11. FF0000
    devtrench said on August 4th, 2008 at 11:01 am

    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.

    [Reply]

  12. FF0000
    River Girl said on August 4th, 2008 at 11:18 am

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

    [Reply]

  13. FF0000
    VaBeachKevin said on August 4th, 2008 at 11:37 am

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

    [Reply]

  14. FF0000
    ShoeMoney said on August 4th, 2008 at 11:50 am

    hmm it should be working try again

    [Reply]

  15. FF0000
    Bryn (Internet Is My Life) said on August 4th, 2008 at 12:00 pm

    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.

    [Reply]

  16. FF0000
    VaBeachKevin said on August 4th, 2008 at 12:05 pm

    2nd try

    [Reply]

  17. FF0000
    Geiger said on August 4th, 2008 at 12:06 pm

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

    [Reply]

  18. FF0000
    ShoeMoney said on August 4th, 2008 at 12:06 pm

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

    [Reply]

  19. FF0000
    wesley said on August 4th, 2008 at 12:15 pm

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

    [Reply]

  20. FF0000
    Patrick said on August 4th, 2008 at 12:16 pm

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

    [Reply]

  21. FF0000
    VaBeachKevin said on August 4th, 2008 at 12:22 pm

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

    [Reply]

  22. FF0000
    Andrew said on August 4th, 2008 at 12:28 pm

    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)

    [Reply]

  23. FF0000
    Architecture said on August 4th, 2008 at 12:31 pm

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

    [Reply]

  24. FF0000
    TEKFIRM said on August 4th, 2008 at 12:45 pm

    he should have mentioned you at least in the contributors !

    [Reply]

  25. FF0000
    Start Blogging said on August 4th, 2008 at 12:50 pm

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

    [Reply]

  26. FF0000
    newmediaMike said on August 4th, 2008 at 12:59 pm

    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.

    [Reply]

  27. FF0000
    meethere said on August 4th, 2008 at 1:00 pm

    Now thats something interesting..
    Thanks joost and shoe.

    [Reply]

  28. FF0000
    TEKFIRM said on August 4th, 2008 at 1:18 pm

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

    most bot spam are like 1000words+

    [Reply]

  29. FF0000
    ShoeMoney said on August 4th, 2008 at 1:26 pm

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

    [Reply]

  30. FF0000
    TEKFIRM said on August 4th, 2008 at 1:51 pm

    any ban plugin to be released soon ? :P

    [Reply]

  31. FF0000
    cheap used cars said on August 4th, 2008 at 2:17 pm

    sure, but sometimes less is more.

    [Reply]

  32. FF0000
    entrenewbie said on August 4th, 2008 at 2:32 pm

    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.

    [Reply]

  33. FF0000
    Monchster said on August 4th, 2008 at 2:42 pm

    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.?

    [Reply]

  34. FF0000
    Dogs said on August 4th, 2008 at 2:48 pm

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

    [Reply]

  35. FF0000
    Webmaster Forums said on August 4th, 2008 at 2:58 pm

    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!

    [Reply]

  36. FF0000
    Justin Cook said on August 4th, 2008 at 3:04 pm

    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.

    [Reply]

  37. FF0000
    Talk Binary said on August 4th, 2008 at 3:40 pm

    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!

    [Reply]

  38. FF0000
    Winning Startups said on August 4th, 2008 at 4:50 pm

    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.

    [Reply]

  39. FF0000
    TYCP Entertainment Magazine said on August 4th, 2008 at 4:53 pm

    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.

    [Reply]

  40. FF0000
    Melvin said on August 4th, 2008 at 5:04 pm

    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…

    [Reply]

  41. FF0000
    Vacation Rentals said on August 4th, 2008 at 5:29 pm

    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.

    [Reply]

  42. FF0000
    Ultimate Blogging Experiment said on August 4th, 2008 at 6:25 pm

    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.

    [Reply]

  43. FF0000
    Erica DeWolf said on August 4th, 2008 at 7:00 pm

    Great tip- thanks so much for sharing!!!

    [Reply]

  44. FF0000
    Miguel Verissimo said on August 4th, 2008 at 7:43 pm

    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.

    [Reply]

  45. FF0000
    Miguel Verissimo said on August 4th, 2008 at 7:45 pm

    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…

    [Reply]

  46. FF0000
    ajaz said on August 4th, 2008 at 10:19 pm

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

    [Reply]

  47. FF0000
    Rajaie AlKorani said on August 4th, 2008 at 11:15 pm

    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.

    [Reply]

  48. FF0000
    Zak Show said on August 4th, 2008 at 11:33 pm

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

    [Reply]

  49. FF0000
    Agent Magenta said on August 5th, 2008 at 12:54 am

    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.

    [Reply]

  50. FF0000
    Sire said on August 5th, 2008 at 1:10 am

    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’ ;)

    [Reply]

  51. FF0000
    Instant Community said on August 5th, 2008 at 1:37 am

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

    [Reply]

  52. FF0000
    Mubin said on August 5th, 2008 at 3:41 am

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

    [Reply]

  53. FF0000
    Dick said on August 5th, 2008 at 6:45 am

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

    [Reply]

  54. FF0000
    Blue SEO said on August 5th, 2008 at 1:34 pm

    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.

    [Reply]

  55. FF0000
    leshii said on August 6th, 2008 at 10:17 am

    Thank’s thas’s im looking for

    [Reply]

  56. FF0000
    ShoeMoney said on August 6th, 2008 at 1:05 pm

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

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

    [Reply]

  57. FF0000
    Jef said on August 6th, 2008 at 3:09 pm

    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.

    [Reply]

  58. FF0000
    Omar said on August 8th, 2008 at 1:20 am

    hahaha good alternative but
    this really work ? :)

    look leshii post hahaha

    [Reply]

  59. FF0000
    terminator69 said on August 8th, 2008 at 6:38 am

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

    [Reply]

  60. FF0000
    Mario said on August 9th, 2008 at 4:29 am

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

    [Reply]

  61. FF0000
    Jeff Finch said on August 12th, 2008 at 11:48 am

    Thanks for letting me know about this ;)

    [Reply]

  62. FF0000
    twig said on August 14th, 2008 at 6:32 am

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

    [Reply]

  63. FF0000
    Nicholas Chase said on August 14th, 2008 at 11:17 am

    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/

    [Reply]

  64. How To Tweak Your Web Site or Blog? said on August 4th, 2008 at 12:02 pm

    [...] was reading the most recent post from ShoeMoney.com this morning and saw that he had asked Joost de Valk to make a WordPress plugin [...]

  65. [...] plugin today to help us in the battle against useless and unwelcome comment spam. The short comment spam solution proposed by ShoeMoney an internet marketing professional and blogger was built into a the Minimum [...]

  66. Wordpress Plugin gegen Kommentar-Spam - Dirks-Webecke said on August 4th, 2008 at 4:26 pm

    [...] wurde dieses Plugin von Shoemoney, der wohl jedem Blogger bekannt sein dürfte. Der teilte seine Idee seinem Freund Joost de Valk [...]

  67. Wordpress Spamschutz: minimale Kommentarelänge said on August 5th, 2008 at 2:48 am

    [...] mit einem Link finden sich mittlerweile unter vielen Artikeln und deshalb gibt es bei Shoemoney ein kleines Plugin, das genau diese Art der Spamkommentare verhindern soll: Minimum Comment Content [...]

  68. Kampf dem Kommentar-Spam « AdClicks-Agent.de said on August 6th, 2008 at 5:39 am

    [...] nachdenken, wie sie das Problem in den Griff bekommen können. Seit einigen Tagen ist es angesagt, besonders kurze Kommentare (kleiner 25 Zeichen) automatisch als Spam zu markieren und herauszufiltern, damit man Kommentare [...]

  69. [...] This is the 2nd post in a series on how to fight wordpress comment spam.  You can read the first post on minimum comment content here. [...]

  70. [...] This is the 2nd post in a series on how to fight wordpress comment spam.  You can read the first post on minimum comment content here. [...]

  71. Website Marketing Strategies August 9th said on August 9th, 2008 at 7:18 pm

    [...] has two good posts about simple fixes to reduce comment spam on your blog. One is a minimum content requirement, and the other is using the Wordpress discussion [...]

  72. [...] Wordpress Minimum Comment Content Length - Fighting Comment Spam [...]

What do you think? Join the discussion...

How do I change my avatar?

Go to gravatar.com and upload your preferred avatar.