Oct
13th

Hacking WordPress: Removing Nofollow from the Source

Thanks for stopping by my personal blog on Marketing Technology! Over 50,000 visitors a month find my content worth returning for, so don't forget to subscribe to the Marketing Technology Blog RSS feed or to the Marketing Technology Email to have new content sent directly to your inbox. You may also find my other business blog helpful, Social Media Domination.

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, WP 2.6: line 116). 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!

You might also find these posts interesting:

RSS feed | Trackback URI

38 Comments »

Comment by no imageWilliam Tully (SezWho)
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)

Rate this:
2.9
Comment by no imageDouglas Karr (SezWho)
2007-10-17 20:44:05

Within one of the WordPress forum, that was a common thread, William!
Rate this:
2.9
 
 
Comment by no imageDotty (SezWho)
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

Rate this:
1.6
Comment by no imageDouglas Karr (SezWho)
2007-11-09 10:45:40

Thanks Dotty! I can read comments like that all day!
Rate this:
2.9
 
 
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 no imageproperty investor (SezWho)
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.
Rate this:
2.9
Comment by no imageDouglas Karr (SezWho)
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

Rate this:
2.9
 
 
Comment by no imageJeff Houdyschell (SezWho)
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

Rate this:
2.9
 
Comment by no imageGroovy Mom (SezWho)
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!!

Rate this:
3.0
 
Comment by no imageClarissa (SezWho)
2007-12-10 10:53:06

Thanks, I changed it too. Much appreciated.
Rate this:
1.6
 
Comment by no imageJerome Baum (SezWho)
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

Rate this:
1.6
 
Comment by no imageRyan McCue (SezWho)
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 :)
Rate this:
3.0
 
2008-01-09 10:35:04

[...] is the hack from Douglas Karrs site. Removing WordPress rel=nofollow on Comment [...]
 
Comment by no imageMisha (SezWho)
2008-03-02 17:18:45

Wow!

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

Misha
Mapquest

Rate this:
3.2
 
Comment by no imageMari Adkins (SezWho)
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. ;)
Rate this:
3.0
 
Comment by no imageKurt (SezWho)
2008-04-03 10:21:33

Found on line 154 in Wordpress 2.5 - Great Hack
Rate this:
1.6
Comment by no imageDouglas Karr (SezWho)
2008-04-03 10:48:57

Thanks, Kurt! I’ve updated this post for WordPress 2.5.
Rate this:
2.9
 
 
Comment by no imageMichael (SezWho)
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

Rate this:
1.6
 
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 no imageDorothy (SezWho)
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
Rate this:
3.0
 
Comment by no imagethatsme (SezWho)
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.
Rate this:
3.0
 
Comment by no imageGiovanni (SezWho)
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?

Rate this:
1.6
 
Comment by no imageGunawan (SezWho)
2008-04-22 23:11:11

Thank’s you for your information.
Rate this:
1.6
 
Comment by no imageFlash design (SezWho)
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 ?
Rate this:
1.6
 
Comment by no imageLutfi (SezWho)
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?
Rate this:
3.0
Comment by no imageDouglas Karr (SezWho)
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

Rate this:
2.9
 
 
Comment by no imageJennifer Bogart (SezWho)
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.
Rate this:
1.6
 
Comment by no imageMikeV (SezWho)
2008-05-04 23:15:25

Did the mods but is there a way to remove nofollow from existing comments?

Thanks-

Rate this:
1.6
 
Comment by no imageLuis Narvaez (SezWho)
2008-05-19 23:58:37

Thanks Douglas for this nice tip I think do follow is the way to go, and about Page Rank issues there are many PR6 do follow blogs around so personally I don’t think well moderated comments spoil Page Rank.
Rate this:
1.6
 
Comment by no imageBlog Bloke (SezWho)
2008-07-02 22:07:05

Done! Thanks Doug
Rate this:
2.8
 
Comment by no imageBlog Bloke (SezWho)
2008-07-09 20:41:43

By the way Doug, what do you think about this article:

http://mixedmarketarts.com/2008/02/12/top-9-reasons-dofollow-can-hurt-your-blog/

Do you believe removing “nofollow” leeches our pagerank? I would be interested in your opinion on that.

…BB

Rate this:
2.8
Comment by no imageDouglas Karr (SezWho)
2008-07-09 23:00:00

I honestly don’t believe a single point he’s made, Bloke. Since I moderate my comments and verify the source, I do a good job of keeping the spammers out and having great conversations with my readers. They deserve credit for those conversations!

I think you’re similar to me, we don’t just write on our blog, we like to engage! That means we pay attention to the comments - not simply letting them run amuck.

Rate this:
2.9
 
 
Comment by no imageBlog Bloke (SezWho)
2008-07-10 01:23:44

It’s something that I’ve often pondered myself.

Will “dofollow” blog comments linking to irrelevant or poorly ranked blogs end up hurting our pagerank?

Hmm, I hope not. I’m really not sure myself and there doesn’t seem to be a lot of discussion out there about it.

Only time will tell I suppose. Let me know if you find any more information will you please?

Thanks Doug.

Rate this:
2.8
Comment by no imageDouglas Karr (SezWho)
2008-07-10 11:51:57

Hi Bloke,

I found this in-depth article over at SEOMoz:

Search engines cannot afford to remove all pages that are linked to by spam pages for precisely this reason - intelligent spammers point their links to themselves, their competition and their community. It would take significant effort to reveal which pages are spam and which are natural, which is exactly the point of these more modern, sophisticated artificial link schemes.

Doug

Rate this:
3.2
Comment by no imageBlog Bloke (SezWho)
2008-07-10 20:54:40

So I guess those SEO types who tell us to only link to quality and relevant links are talking through their hats (white or black). :-)
Rate this:
3.5
 
 
 
Comment by no imageBlog Bloke (SezWho)
2008-07-10 01:24:59

By the way, I would like to invite you to write a guest post @ Blog Bloke dot com. Let me know and I will send you an invite login.

Cheers,

…BB

Rate this:
2.8
 
2008-07-20 08:37:51

[...] to do it, but to make sure that ‘I’ don’t screw up your Wordpress installation, here’s a proven, reliable tutorial. Make sure you back your files before proceeding with the [...]
 
2008-08-17 04:28:59

Thank you so much for this help. I have been trying to find the code that was hidden in! After reading this it took me 3 minutes!
Rate this:
2.5
 
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.
  • Use your real name, not some keywords. Otherwise it will 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!