Winternet

WordPress Comment Spam nofollow Hack

Filed under: — jwinter on 1/22/2005 at 5:04 pm

I guarantee WordPress will have a better way to do this in the future, but for now, if you want to add "rel='nofollow'" attributes to all of the links in the comments to your blog, here’s how:

  1. Open up template-functions-comment.php
  2. Replace lines 124-128 with
    if (empty($url)) :
    echo $author;
    else: #Update 2005-01-22 Adding nofollow support.
    echo "<a href='$url' rel='nofollow'>$author</a>";
    endif;
  3. Replace line 177 with
    $comment_text = apply_filters('comment_text', $comment_text);
    $comment_text = str_replace('<a ', '<a rel="nofollow" ', $comment_text);
  4. Check the comments on your site to ensure you didn’t screw up your WP installation.

Doing this doesn’t prevent comment spam on your site, but it does prevent Google from giving spammers any PageRank points, which is why spammers spam in the first place.
More information:

  1. Google Blog on Nofollow for Comment Spam
  2. Phil Rignalda on Nofollow

0.083 || Powered by WordPress