How to add no follow rel for comments in wordpress ?

9. January 2010

You need to look at my code and edit your code accordingly, before that please read post carefully and create a backup of file functions.php

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

Code:

  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');

 

Good Luck !

 

Tips n Tricks

Comments

3/6/2010 9:49:58 AM #
I have never seen such a great blog and allposts seem to be original.

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading