In order to “Uphold” Google PageRank juice and do not let it make damage to websites you're linked to (which is not confirmed from Google, but still), only one manner to add nofollow links to your external links.
May get it done easily using plugins as – External Nofollow.
May you don't like the think of plugin and would like to have the more command over how the nofollow attribute works (and saving some server load too of course), you could do it with a small bit of code.
add_filter('the_content', 'my_nofollow');Adding the above piece of code to your functions.php will add the nofollow link attribute to all external links while excluding all internal links. Try it out.
function my_nofollow($content) {
//return stripslashes(wp_rel_nofollow($content));
return preg_replace_callback('/]+/', 'my_nofollow_callback', $content);
}
function my_nofollow_callback($matches) {
$link = $matches[0];
$site_link = get_bloginfo('url');
if (strpos($link, 'rel') === false) {
$link = preg_replace("%(href=S(?!$site_link))%i", 'rel="nofollow" $1', $link);
} elseif (preg_match("%href=S(?!$site_link)%i", $link)) {
$link = preg_replace('/rel=S(?!nofollow)S*/i', 'rel="nofollow"', $link);
}
return $link;
}
Adding the above piece of code to your functions.php will add the nofollow link attribute to all external links while excluding all internal links. Try it out.
} function my_nofollow_callback($matches) { $link = $matches[0]; $site_link = get_bloginfo('url'); if (strpos($link, 'rel') === false) { $link = preg_replace("%(href=S(?!$site_link))%i", 'rel="nofollow" $1', $link); } elseif (preg_match("%href=S(?!$site_link)%i", $link)) { $link = preg_replace('/rel=S(?!nofollow)S*/i', 'rel="nofollow"', $link); } return $link; }