Remove nofollow From WordPress Comments

by Blog Tips on July 16, 2010

Great little function to remove nofollow attribute from comments in wordpress. No need to use the dofollow plugin anymore, this is faster.

The code

Place the snippet bellow in your theme’s functions.php file.

function xwp_dofollow($str)
{
 $str = preg_replace(
 '~<a ([^>]*)\s*(["|\']{1}\w*)\s*nofollow([^>]*)>~U',
 '<a ${1}${2}${3}>', $str);
 return str_replace(array(' rel=""', " rel=''"), '', $str);
}

remove_filter('pre_comment_content',     'wp_rel_nofollow');
add_filter   ('get_comment_author_link', 'xwp_dofollow');
add_filter   ('post_comments_link',      'xwp_dofollow');
add_filter   ('comment_reply_link',      'xwp_dofollow');
add_filter   ('comment_text',            'xwp_dofollow');

Well done ! Try it yourself .

Did you enjoy this article? Give us some link love, and don't forget to bookmark this page on Delicious.

Notes : Join us and read the Guidelines to submit your guest posts.
Subscribe free updates via: RSS Feed | Email | Twitter

Related Articles

{ 22 comments… read them below or add one }

1 Tech Maish July 16, 2010 at 7:50 am

In my opinion removing nofollow from wordpress is not a good idea. Now a days spammers are using different techniques.

Yesterday a spammer posted a comment on my blog, it was looking fine, but after carefully reviewing it if found that he used (.) and (!) as his anchor text.

In your wordpress Dash Board you will not see links in a comments, but if you edit the comment, you will find there.

Dofollow blogs will then receive lots of spam comments if they will remove nofollow attribute.

Its upto you, that whether you want to spend more time on reviewing comments Or Posting new blog posts.

Reply

2 Hung | JVPRIME August 9, 2010 at 7:25 am

Thanks for your warning.
We need to look comments carefully.

Reply

3 Hieu Martin July 16, 2010 at 8:08 am

I agree with you remove the nofollow wordpress is not a good idea. But in some time admin will need to remove the nofollow of wordpress

Reply

4 Hung | JVPRIME August 9, 2010 at 7:28 am

We can remove no-follow for regular visitors after they reach numbers of comment by using plugin (for wordpress).

Reply

5 Shiva | Web Magazine July 16, 2010 at 11:56 am

Well keeping a blog do follow or now follow has been an issue of debate for a long time .Lets not get into That, thanks for the snippet Hieu

Reply

6 Hieu Martin July 23, 2010 at 5:50 pm

You are welcome shiva. Thanks for comment .

Reply

7 TechChunks July 16, 2010 at 2:05 pm

Great! I like to avoid plugins as long as I can accomplish the same effect via direct code snippet. it is lighter on the page load speed, as well.

Reply

8 Hieu Martin July 16, 2010 at 2:34 pm

@Techchunks i think so . Code it is lighter on the page load speed than plugin :)

Reply

9 Trent Cary July 17, 2010 at 8:59 am

Yes indeed. It’n not a good idea to have dofollow blog. I just can’t support spammers anymore.

Reply

10 What causes obesity July 17, 2010 at 8:45 pm

Thank you,
I hate “nofollow”. The Internet is based on links and “nofollow” kills them. No links – no Internet.
I’m going to implement this plugin today.

Reply

11 Hieu Martin July 24, 2010 at 2:17 am

Ok try it yourself now . Good luck

Reply

12 Classifs July 18, 2010 at 8:30 am

Thanks for the useful info! Promote DoFollow.

Free Indian Classifieds

Reply

13 Daddy Dazed July 20, 2010 at 10:41 pm

I support the remove nofollow movement. Feel fre eto vist my website and leave a comment

Reply

14 Hieu Martin July 24, 2010 at 2:16 am

i’m check it out now ^^

Reply

15 Moondancer July 31, 2010 at 10:14 am

Oh thanks for including this code, the less WordPress Plug-ins I have the happier I am.

Even when my sites weren’t do follow (about five years ago) I was still getting spam. Install a few good anti spam plugins and you’ll catch most of it in the spam folder. I review whatever a person writes on my site & reply to their comment, so it’s not an added step for myself. The first time a person comments on any of my sites their comment is moderated.

Reply

16 festival arts August 18, 2010 at 11:11 am

Nofollow seemed like a good idea when it was first designed, but it shouldn’t be enabled by default in future WordPress releases, because :)

Reply

17 Let's Share August 20, 2010 at 3:17 am

Great, maybe someday I will try, currently I only activate the DoFollow on Top Commentators Widget

Reply

18 Sathish @ TechieMania September 24, 2010 at 4:49 pm

Thanks for sharing the snippet. But I am not gonna use it now.

Reply

19 mincir September 26, 2010 at 7:43 am

This is great job to deliver the code to do some sort action.

Reply

20 Web Designer October 6, 2010 at 10:21 am

Thanks for Sharing Very Useful and Helpful Post, Keep Writting That Kind of Posts :)

Reply

21 Thomas Scholz October 9, 2010 at 11:36 am

Please restore the GPL notice from the the source at http://toscho.de/2009/no-no-no-nofollow/ – thanks!

BTW, removing the nofollow value didn’t influence the amount of spam on any blog I manage. Spammers just don’t care about that.

Reply

22 Felicia @ No Deposit Poker April 28, 2011 at 5:02 am

Removing nofollow from WP can be a good idea, but of course we need to watch out for spammers too. Thanks Hieu for the tips on how to remove nofollow from WP comments.

Reply

Leave a Comment

{ 3 trackbacks }

Previous post:

Next post: