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
What Next?
- Tweet this Post
- Digg this Article
- Stumble this article
- Technorati this post
- Bookmark on del.icio.us






{ 22 comments… read them below or add one }
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.
Thanks for your warning.
We need to look comments carefully.
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
We can remove no-follow for regular visitors after they reach numbers of comment by using plugin (for wordpress).
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
You are welcome shiva. Thanks for comment .
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.
@Techchunks i think so . Code it is lighter on the page load speed than plugin
Yes indeed. It’n not a good idea to have dofollow blog. I just can’t support spammers anymore.
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.
Ok try it yourself now . Good luck
Thanks for the useful info! Promote DoFollow.
Free Indian Classifieds
I support the remove nofollow movement. Feel fre eto vist my website and leave a comment
i’m check it out now ^^
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.
Nofollow seemed like a good idea when it was first designed, but it shouldn’t be enabled by default in future WordPress releases, because
Great, maybe someday I will try, currently I only activate the DoFollow on Top Commentators Widget
Thanks for sharing the snippet. But I am not gonna use it now.
This is great job to deliver the code to do some sort action.
Thanks for Sharing Very Useful and Helpful Post, Keep Writting That Kind of Posts
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.
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.
{ 3 trackbacks }