dean.edwards.name/weblog/2005/03/nofollow/

Removing “nofollow” from WordPress 1.5

Why?

I’ve been totally swayed by an article by Phil Ringnalda. My weblog is spam-free. If people want to contribute comments and links then I am happy to pass on some of my page rank. Likewise, if bloggers link to me, I’d like to get some of their reflected glory. Because my site is pretty well moderated, I don’t have to assume that comments are spam. Trackbacks are another matter of course :-(. I now moderate all trackbacks/pingbacks to avoid this form of spam.

How?

Put the following code in the WordPress file my-hacks.php. It will remove the nofollow directive for both links in comments and to the author’s home page.

<?php
// -------------------------------------------------------------------------
// REMOVE "NOFOLLOW"
// -------------------------------------------------------------------------

function comment_author_remove_nofollow($text) {
    return preg_replace("/(<a href='[^']*') rel='external nofollow'/", "$1 rel='external'", $text);
}

function comment_remove_nofollow($text) {
	return preg_replace("/(<a href='[^']*') rel='nofollow'/", "$1", $text);
}

// remove/replace filters
remove_filter('pre_comment_content', 'wp_rel_nofollow', 15);
add_filter('comment_text', 'comment_remove_nofollow');
add_filter('get_comment_author_link', 'comment_author_remove_nofollow');
?>

Comments (14)

Leave a comment

Christoph Rummel’s NoNofollow plugin does exactly this, plus provides an option in the administration interface for activating the no-nofollow functionality only after a specified amount of days.
  • Comment by: Basil Crow
  • Posted:
Darn. I wasted an hour then. I tried Googling for similar but found very little. Oh well.
  • Comment by: -dean
  • Posted:

You can also try WordPress 1.5 Plugin – Strip “nofollow” tag from comment URLs.

The core difference with your code is that instead of processing comment_text to remove rel=nofollow, it replaces the function make_clickable so the tag is not added in the first place possibly saving some time.

I couldnt get the other plugin to work, but this is working a treat. Cheers

  • Comment by: Tom
  • Posted:

Nice job. I’d just searched the WP folder on my hard drive and removed the nofollow instances. That’s probably too involved, but as it turns out, many of us were right in saying (way back when) that nofollow would not stop blogspam.

  • Comment by: DianeV
  • Posted:

[…] ess Nofollow Remover Plugin Thanks to Nick, I note that Dean Edwards has come up with a nofollow remover plugin for WordPress. I’d simply found the nofollow code and r […]

[…] llow Kategorie: internal Ich schließe mich der Fraktion an. Anstatt des Hacks verwende ich lieber das Plugin von bronski.net. Scheint mit meiner 1.5er Version zu funkt […]

Trackbacking your entry… […] As good as their intentions were, this is definitely not serving the purpose, in fact it may have even trigger more trackback spam, .. So I think if people contribute to my blog by adding a comment they deserve a link, a real link without a nofol…

I think i’ll use that code on my blog, afterall, I don’t see many advantages ( for me ) in having nofollow on all comment links.

Being searching for this for a while, excellent resource, works very well:D

  • Comment by: Blogcrowds
  • Posted:

I’m back, ages later. I was trying to remove nofollow from WordPress 2.0.5; I removed *every* instance, and still nofollow was added (not quite sure how that works …).

At any rate, this code works perfectly, and I thank you because I’m of a similar opinion — that if people take the time to contribute, it’s poor manners to mark their links with something that denigrates them, even if only digitally to a search engine.

Thanks again.

I was searching how to remove “nofollow” from wordpress comments. Thanks for the info.

There is an excellent case for removing no-follow but perhaps ideally there would be some way of doing it after a small number of comments rather than straight away so as not to encourage spammers?

  • Comment by: Firefox CE
  • Posted:

[…] Removing Nofollow: No fan of nofollow, for the first time in WP2.0.x, I was unable to remove it — but found Dean Edwards’ Nofollow Remover Plugin quite excellent. Throw the code into your my-hacks.php file, upload it to your WordPress root, enable legacy my-hacks.php file support (Options > Miscellaneous), and you’re done. […]

Comments are closed.