The best way to prevent spammer from posting comments is by removing the 'homepage' field from your comment form. I'll show you how.

Best way to fight spam comments on Drupal websites

11/11/2015 - 10:53

I've tried everything to get rid of those annoying spammers: Honeypot, HTTP:BL, Spamicide, mollom, and the list goes on. But the thing that eliminated almost (if not) all the spam comments was adding the following piece of code to my template.php (credits for the code go to mengi): ​

function themename_form_comment_form_alter(&$form) {
  $form['author']['homepage']['#access'] = FALSE;
}

And change 'themename' into the name of your theme. This removes the 'homepage' field from your comment forms. Apparently there is no more incentive for spammers to post comments as they can't leave a URL to direct users to. Of course the downside is that your visitors can't leave a link to their homepage as well. But it's an offer I'm willing to make in order to fight the massive amounts of comment spam I was getting.

You can find your template.php file by logging in to the server which hosts your Drupal files with (S)FTP and browsing to your theme folder. Your theme folder is most likely located at:

/sites/all/themes/themename/template.php

You can put the piece of code anywhere you like. Don't forget to replace 'themename' in the piece of code which is the same as the folder where the template.php file is located.

Got questions? Leave a comment!

Want to become a Drupal Expert?

Subscribe to my newsletter and receive e-mails with the latest Drupal tutorials, tips and tricks.