July 23, 2009 | Posted by Manchumahara(Sabuj Kundu) in category Wordpress themes, wordpress, wordpress plugin with tags , ,

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, 604 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 ?

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

9 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. Bony Yousuf says:

    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.

    • Manchumahara says:

      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.

Leave a Reply

Additional comments powered by BackType

feedback