Google to the rescue!
Wednesday, 19 January 2005
In an attempt to combat comment spam, Google, MSN, Yahoo and a number of other companies have agreed to support the rel=”nofollow” attribute on links.
If you’re a blogger (or a blog reader), you’re painfully familiar with people who try to raise their own websites’ search engine rankings by submitting linked blog comments like “Visit my discount pharmaceuticals site.” This is called comment spam, we don’t like it either, and we’ve been testing a new tag that blocks it. From now on, when Google sees the attribute (rel=”nofollow”) on hyperlinks, those links won’t get any credit when we rank websites in our search results. This isn’t a negative vote for the site where the comment was posted; it’s just a way to make sure that spammers get no benefit from abusing public areas like blog comments, trackbacks, and referrer lists.
I’ve modified Nucleus, which I am using on my blogging software, to support the rel=”nofollow” attribute and hope others will follow too. Instructions on how to modify Nucleus are inside…
COMMENT.php
First find the COMMENT.php
file in the nucleus/libs
directory. At the bottom of this file you will find the createLinkCode()
function which you will need to modify.
At the bottom of the createLinkCode()
function, on line 126 or so, you will find something that looks like this:
return $pre . '<a href="'.$linkedUrl.'">'.shorten($displayedUrl,30,'...').'</a>' . $post;
Simply modify this line to this:
return $pre . '<a href="'.$linkedUrl.'" rel="nofollow">'.shorten($displayedUrl,30,'...').'</a>' . $post;
COMMENTS.php
Next you need to open the COMMENTS.php
file in the same directory and go to the parse_userlink()
function. On or around line 378 you’ll find the following line:
echo '<a href="'.$this->currentComment['userlinkraw'].'">'.$this->currentComment['user'].'</a>';
Modify this line to:
echo '<a href="'.$this->currentComment['userlinkraw'].'" rel="nofollow">'.$this->currentComment['user'].'</a>';
ADMIN.php
Finally you need to open the ADMIN.php
file in the same directory and go to the action_commentedit()
function. On or around line 1326 you’ll find the following line:
$comment['body'] = eregi_replace("<a href=['\"]([^'\"]+)['\"]>[^<]*</a>","\\1",$comment['body']);
Modify this line to:
$comment['body'] = eregi_replace("<a href=['\"]([^'\"]+)['\"]( rel=\"nofollow\")?>[^<]*</a>","\\1",$comment['body']);
And you’re done!
rakaz, you missed out the userid link, if you want that to be non-page-ranking
as well, just modify line 378 in COMMENTS.php (note the plural S)
from
echo ‘currentComment['userlinkraw'].
‘">’.$this->current Comment['user'].’‘;
into
echo ‘currentComment['userlinkraw'].
‘">’.$this->current Comment['user'].’‘;
hmm, nucleus doesn’t like this code at all…
Thanks xiffy… I’ve updated the instructions to include the userid link.
I did just the same this morning. But the thing is, spammers won’t care if you or I do so, unless it’s included in all future releases of Nucleus.
Just my 2c ;-)
rakaz, have you found a solution for line 1326 in ADMIN.php where the comment is retrieved for editing? The reverse proces; changin the link back to text is borked with the applied patches. Hadn’t got time to investigate and patch this bug yet myself …
hmm, didn’t think of that… I’ll take a look at it in a moment
Added extra instruction for ADMIN.php. Editing links should work again…
Is this something that could easily be added to Nucleus via a plugin or a template?
:-) your fast!
In the “Preventing comment spam” post on the Google Blog, Google has now officially announced that they will longer be consider links attributed with rel=”nofollow” when calculating pagerank scores.
Nice work! I will implement this tonight. :)
I just implemented it. It’s applied to new comments only, right?
Good stuff rakaz! It works great
Joaquin,
My understanding is it works for old comment as well. I tested it on my blog from a old post and it works.
cheers
Spammers,
Go away from me! It’s not going to help your links’ ranking by spamming here.
rakaz
admun, joaquin: Because text of comments and any URL contained in the text are stored in HTML form in the database and not processed before being displayed, this won’t work for older comments. However, if you edit an existing comment it will add the rel="nofollow" attribute.
The URL of the comment (if specified) is processed at the time it is displayed, so rel="nofollow" will be added to the URL for all comments, even older ones.
OK! Thanks for this post, by the way. :)
Why not add a PreAddComment plugin for existing 3.x versions of Nucleus that would replace any links with the nofollow version of them? Admittedly, it wouldn’t solve the problem for existing commentspam, but any new links in comments would be properly nofollowed.
nice
Cool design, great info!