Adding no follow for links in wp comments

Don't Follow MeOne of my senior brother just asked me, how to add no follow rel for comments in wordpress. May be there is plugin for this. Look to my code :)
How to use:
1.Open the functions.php file in ur current theme and put these code within php tags.

What it will do:
1. Will add ‘no follow’ as rel in url , if comment contains any url.
2. Will ad ‘external’ as rel in url , if comment contains any url.
3. Will add target=”_blank” in comment author’s url so that their web url open’s in new window/new tab as in browser settings
4. Will add target=”_blank” to url, if comment contains any url
5. Wp adds ‘no follow’, ‘external’ rel in comment author’s url by default. So we don’t need to add this :P

Tips:
1.If possible upgrade to wp2.8.2

      function nofollow($text) {
	        $text = preg_replace('/<a /i','<a rel="nofollow external" ',$text);
	        $text = preg_replace('/<a /i','<a target="_blank" ',$text);
	        return $text;
    }
    function targetblank($text){
    		$text = preg_replace('/<a /i','<a target="_blank" ',$text);
	        return $text;
    }

    add_filter('comment_text', 'nofollow');
    add_filter('get_comment_author_link','targetblank');

any question ask me :)
p.s.: post image is just for fun :P

BTW, are you afraid of editing your functions.php ? Ok, no problem you can add the above piece of code using the bellow wp plugin.

  Wp nofollow plugin for comment (997 bytes, 995 hits)

Duh, you are totally unhappy with this post, na ? You can to treat your commentors with “cake and cook”, ok no problem.Just forget my post and read this blog post …“The Single, Most Profound Way To Thank Your Commenters”.
Happy now ?

Last Update on January 18th, 2010

This entry was posted in wordpress, Wordpress Plugin, Wordpress Themes and tagged , , . Bookmark the permalink.

12 Responses to Adding no follow for links in wp comments

  1. Omi Azad says:

    He He He
    I want to make people lost!

  2. Karigor Hasan says:

    ভালো হ্যাক মানচু ভাই! কাজে লাগবে!

  3. nezam says:

    এই “নো ফলো” এইটা কি জিনিস ভাইজান?

  4. thanks man… i’ve been looking for these..

  5. rayhan says:

    sabuj, excellent solution. will definitely use. should we use the plugin or functions.php hack? please advise.

    • Dear rayhan vai, I think u didn't read the post details. Please check there are two ways. You can direct edit ur functions.php file to add the codes or use as plugin that is given for download which will do same thing and u don't need to edit functions.php . thank you :)

  6. rayhan says:

    thanks sabuj. my mistake. will definitely use it.

  7. Tanmoy says:

    Nofollow and dofollow are two important topic for page rank. If in ur website, dofollow links are kept, your page rank will be affected for that dofollow

  8. speedy18us says:

    Those preg_replaces are good only if the user hasn't inserted in comment the nofollow tag already.

  9. pushpinder says:

    thanks mate – I was looking for this article – worked like a charm!

  10. I want to make people lost!

  11. gamezat says:

    hello,

    it's good but not too much secure

    becouse you use

    <a

    ok but if the use add

    <A A Letter is cap

    thank you

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>