in WordPress, Wordpress Plugin, Wordpress Themes

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 😛

Tips:
1.If possible upgrade to wp2.8.2

[code language=”php”]
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’);
[/code]

any question ask me 🙂
p.s.: post image is just for fun 😛

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.
[download id=”9″]

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 ?

12 Comments

  1. 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

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

  3. 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

  4. 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 🙂

  5. āĻāĻ‡ “āĻ¨ā§‹ āĻĢāĻ˛ā§‹” āĻāĻ‡āĻŸāĻž āĻ•āĻŋ āĻœāĻŋāĻ¨āĻŋāĻ¸ āĻ­āĻžāĻ‡āĻœāĻžāĻ¨?

  6. āĻ­āĻžāĻ˛ā§‹ āĻšā§āĻ¯āĻžāĻ• āĻŽāĻžāĻ¨āĻšā§ āĻ­āĻžāĻ‡! āĻ•āĻžāĻœā§‡ āĻ˛āĻžāĻ—āĻŦā§‡!

Comments are closed.