web analytics

How to add no follow rel for comments in wordpress ?

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 !

Site last updated May 22, 2013 @ 3:30 pm; This content last updated September 21, 2012 @ 8:45 pm