Oct
13th

Hacking WordPress: Removing Nofollow from the Source

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

30 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.5
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.5
 
 
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:
2.5
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.5
 
 
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:
1.4
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.5
 
 
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:
1.4
 
Comment by no imageClarissa (sezwho)
2007-12-10 10:53:06

Thanks, I changed it too. Much appreciated.
Rate this:
2.5
 
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:
2.5
 
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:
1.4
 
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.0
 
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:
2.5
 
Comment by no imageKurt (sezwho)
2008-04-03 10:21:33

Found on line 154 in Wordpress 2.5 - Great Hack
Rate this:
2.5
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.5
 
 
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:
2.5
 
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:
1.4
 
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:
1.4
 
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:
2.5
 
Comment by no imageGunawan (sezwho)
2008-04-22 23:11:11

Thank’s you for your information.
Rate this:
2.5
 
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:
2.5
 
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:
1.4
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.5
 
 
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:
2.5
 
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:
2.5
 
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:
2.5
 
Comment by no imageBlog Bloke (sezwho)
2008-07-02 22:07:05

Done! Thanks Doug
 
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!