Oct
13th

Hacking WordPress: Removing Nofollow from the Source

RSSIf you like this post, then consider subscribing to my full RSS feed. Subscribe now and you will get an offer that's only available to folks that read my feed!

I had an intermittent problem with my comments where the actual comment text was not appearing. I finally tracked it down to the Dofollow plugin and removed it today. I still actually want to rid my site of rel=nofollow on authors and comments, though. If you would like to read why, here’s a post on what rel=”nofollow” is and how it works.

NOTE: Before you edit any code in WordPress, be sure to back it up first! I’m not responsible if your site gets hosed up. :)

Today I dug into the code and actually identified in WordPress core code where the nofollow edit is made. You can make these edits as well if you’re hosting your own WordPress installation.

Removing WordPress rel=nofollow on Authors

For the author link, the line of code is in wp-includes/comment-template.php (WP 2.3 or older: line 48, WP 2.5: line 114). Replace

$return = "<a href='$url' rel='external nofollow'>$author</a>";

with this:

$return = "<a href='$url' rel='external'>$author</a>";

Removing WordPress rel=nofollow on Comment Text

Links in the actual comments are a little tougher to find. However, I was able to track down where the filter was applied in wp-includes/default-filters.php (WP 2.3 or older: line 125, WP 2.5: line 154). To disable the filter, you need only to remark the link out by putting two forward slashes in front of it. Edit

add_filter('pre_comment_content', 'wp_rel_nofollow', 15);

like this:

//add_filter('pre_comment_content', 'wp_rel_nofollow', 15);

Voila! No more punishing your users for generating great content on your blog! The advantage of doing it this way is that you’re not applying more code later in a plugin to remove the code that was there in the first place. The disadvantage of doing it this way is that you’ll have to update it each time you upgrade WordPress on your site.

Happy Hacking!

RSS feed | Trackback URI

28 Comments »

Comment by William Tully
2007-10-17 19:48:43
Love it! Thanks fuzzy-faced WordPress hacker!

(would be nice if they just coded it in as an option to turn on/off from the options panel)

Comment by Douglas Karr
2007-10-17 20:44:05
Within one of the WordPress forum, that was a common thread, William!
 
 
Comment by Dotty
2007-11-08 21:49:56
Thank you for this post. I have been going nuts trying to find where to remove the nofollow. You are a wonderful resource.

Dotty

Comment by Douglas Karr
2007-11-09 10:45:40
Thanks Dotty! I can read comments like that all day!
 
 
2007-11-08 22:58:41
[...] own blogs this will be useful information. Here is a link to an article for this configuration. Nofollow tag for your blog Deleting the Nofollow tag will be better for your search engine [...]
 
Comment by property investor
2007-11-23 10:51:27
Thanks Douglas. I installed the dofollow plugin, but then removed it again as it was not quite working correctly.
I did a google search and then found your blog. I’ll try out the WP hack later. Hopefully it will get more people commenting on my blog.
Comment by Douglas Karr
2007-11-23 12:03:37
Hi P.I.,

I noticed the same thing and that’s why I made this change! I do think it supports more folks commenting!

Regards,
Doug

 
 
Comment by Jeff Houdyschell
2007-11-23 18:10:46
Thanks Doug, I am going right from here to all my blogs and doing a little hacking.

May even do a short post on my site and refer them here…

Jeff,
WordPress Guides

 
Comment by Groovy Mom
2007-11-25 00:09:01
Gosh, this is such an easy fix, I keep reading it thinking I’m not getting something.

I installed LinkLove yesterday to remove the nofollows. This is a (simpler) no-frills approach. I’ll have to keep it bookmarked, just in case. Thank you!!

 
Comment by Clarissa
2007-12-10 10:53:06
Thanks, I changed it too. Much appreciated.
 
Comment by Jerome Baum
2008-01-02 09:23:47
This is great.

I wish I could make the same change, but my blog is hosted on WordPress.com (see it here), so unfortunately I cannot edit anything (even editing just the CSS costs money, not to talk about editing themes).

Might go for another host, then I will definitely follow your lead on this!

Jerome

 
Comment by Ryan McCue
2008-01-04 06:51:30
I just thought I’d mention, the second part should be possible without commenting it out. You should be able to use the following: remove_filter('pre_comment_content','wp_rel_nofollow'):
Stick that in your template or in a plugin :)
 
2008-01-09 10:35:04
[...] is the hack from Douglas Karrs site. Removing WordPress rel=nofollow on Comment [...]
 
Comment by Misha
2008-03-02 17:18:45
Wow!

That’s a nice hack! Now I can do this without plugin :D Thanks, Douglas :)

Misha
Mapquest

 
Comment by Mari Adkins
2008-03-15 11:40:40
Thanks for this. I’ve been reading a lot of people who are doing this lately - but you’re the first person who’s told me how. ;) I followed along, modded my files, and am saving this for when I do upgrades so I have it. ;)
 
Comment by Kurt
2008-04-03 10:21:33
Found on line 154 in Wordpress 2.5 - Great Hack
Comment by Douglas Karr
2008-04-03 10:48:57
Thanks, Kurt! I’ve updated this post for WordPress 2.5.
 
 
Comment by Michael
2008-04-10 06:46:39
Me and a friend were just talking yesterday about getting rid of the nofollow and we thought that it was just something that we would have to live with.

Then today he sends me this great post!!

I will be making this change immediately. I only hope every blogger out there reads this post

thanks
michael

 
2008-04-10 07:14:18
[...] sent me a great link today on douglaskarr’s marketing technology blog about how you can hack your wordpress code to get rid of the rel=”nofollow” default and start to give your readers the [...]
 
Comment by Dorothy
2008-04-10 12:01:25
I just upgraded my Wordpress Blog - noticed I needed to “rehack” my site. Thanks for having these instructions here. They helped me once again
Dotty
 
Comment by thatsme
2008-04-20 22:49:26
Half the fun of posting comments is so that all involved to get a link back to your own website. Thanks for letting others get this benefit.
 
Comment by Giovanni
2008-04-21 23:54:42
Making the change:

//add_filter(’pre_comment_content’, ‘wp_rel_nofollow’, 15);

The old comments continues with nofollow …

How can I to remove this?

 
Comment by Gunawan
2008-04-22 23:11:11
Thank’s you for your information.
 
Comment by Flash design
2008-04-23 01:39:01
I’m really confused on this area. I do think that the nofollow is not the right way to do it and it ruins it for a lot of other people. However many blogs I used to read got spammed so badly.
Hmmm strange my first comment didn’t get posted. How come ?
 
Comment by Lutfi
2008-04-23 02:40:13
I am a do-follow member too, but i have a doubt. Is it have a bad effect for our PAGERANK?
Comment by Douglas Karr
2008-04-23 10:47:17
Hi Lufti,

If you do not moderate comments and allow link spam into your sites… YES… you can definitely damage your Pagerank. I would not recommend it without moderating comments carefully.

Cheers,
Doug

 
 
Comment by Jennifer Bogart
2008-04-29 10:27:16
Awesome! Thank you! I am a fairly new blogger, and was trying to find this in the code myself, but failed :). So I installed Dofollow, but then, after it was correctly activated etc. the no follow code was still showing up in the comment html when people tried to leave links in their comments! ARGH! Thank you SO much! I just edited my code and am off to uninstall Do Follow now. Found you through a Google search.
 
Comment by MikeV
2008-05-04 23:15:25
Did the mods but is there a way to remove nofollow from existing comments?

Thanks-

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

My Comment Policy: I moderate comments. Please be patient:

  • Spam will happily be destroyed.
  • Mean comments aren't necessary. If I don't post them I will reply personally to let you know why.
  • Lewd comments will be edited, I don't want my readers leaving because of offensive content.
Great debate, criticism and colorful commentary is always appreciated and approved!