Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Reduce WordPress Comment Spam with Cookies for Comments

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Reduce WordPress Comment Spam with Cookies for Comments

A growing site comes with new challenges and one of them is comment spam. Thankfully, there are plenty of solutions to effectively fight comment spam. For example, using Akismet you can effectively reduce comment spam. You can also use CAPTCHA to block spamming bots. In this article, we will show you how to reduce WordPress comment spam with Cookies for Comments.

First thing you need to do is install and activate the Cookies for Comments plugin. The plugin works out of the box and there are no settings for you to configure.

How Cookies for Comments Work?

Most of the comment spam is submitted by spam bots. These spam bots are basically software scripts that crawl the web looking for comment forms and then submit spam comments.

To spam thousands of websites, these programs don’t load images and stylesheets. The text on a page is enough for them to determine the presence of a comment form.

Cookies for comments plugin loads a stylesheet or an image when a page on your WordPress site is accessed. If the user’s browser downloads the stylesheet or image file, then the plugin sets a cookie in the user’s browser.

The plugin checks for the cookie when any user tries to post a comment. If the cookie exists, then this means that the user is not a spam bot.

If the cookie does not exist, then the user is most likely a spam bot, and the comment they submit is marked as spam.

How To Completely Stop The Spam Bots From Commenting

Cookies for Comments will successfully detect spammers, but it will let them post a comment. This comment goes into spam comments. With little more effort, you can stop the bots from posting a comment altogether.

To do that, you will need to find out the cookie value. Right click anywhere on the your website, and then select View Page Source.

Opening page source view in Google Chrome

This will open a new tab in your browser showing the page’s HTML source. You need to scroll down to the bottom of the page until you find a line similar to this one:

<img alt='css.php' src=";o=i&amp;t=201927728" width='1' height='1' />

The value after css.php?k= is the value of the cookie. Like in this example, it is 9692e3a737ecafe8fe6329490410ff50. You will need this value in the next step.

Now you need to connect to your website using an FTP client and edit the .htaccess file. Simply paste this code before anything else in your .htaccess file.

RewriteRule ^wp-comments-post.php - [F,L]

You need to replace XXX with the cookie value.

That’s all. Your .htaccess file will now look for a cookie value and when it is not found, it will stop the user from commenting.

We hope this article helped you reduce WordPress comment spam on your site.

If you liked this article, then please subscribe to our YouTube Channel for more WordPress video tutorials. You can also find us on Twitter and Google+.

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. leetramp says:

    I’m running WP 3.9 and WP warns that this plugin has not been tested with this 3.9. Is this something you can work on resolving? (And, thanks for the what looks like a great plugin!)

    [I’m also running a WP 4.0 site, and I just installed the plugin on both. I’ll let you know if this works for me.]

  2. WPBeginner Staff says:

    No the plugin is designed to check for cookies only for comment submission.

  3. 1Mattman says:

    Will this also work with FS Contact Form if you have one setup with no captcha?

  4. Tony Franco says:

    Very Interesting this Solution! One question, this makes the load more slowly?

  5. Balaji says:

    Nice One…

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.