I built a site for a client in Drupal 7, and it quickly started to gather spammers. I implemented Mollom to filter out a bunch of the spam, but as icing on the cake, to prevent empowering spam links and a deterrent from posting spam comments in the first place, I wanted to make sure all links in the comments were given the rel=“nofollow” attribute like Textpattern does. But, regardless of how many people have asked since 2008-ish, nobody has built this in a way that isn’t handled on a link by link basis, and even then it doesn’t come into play for comments. So, I changed my comment template like so:
The standard code
What it looks like now
$comment_pre = (string) $comment_body['safe_value']; $replace = '<a href="'; $with = '<a rel="nofollow" href="'; $comment_post_edit = str_replace($replace, $with, $comment_pre); echo $comment_post_edit;
What it does, is search each comment for anchor tags and drops a rel=“nofollow” just before the href. Their link still shows up, but search engines ignore it.
Now, if spammers will just take the hint, everything will be golden. But even if they don’t, you won’t have to worry about them getting any SEO points from your site.