Automatikus nofollow a kimenő linkekre.

A WordPress automatikusan nem tesz nofollow attribútumot a bejegyzésekből, oldalakból kimenő linkekre.
Ezen fogunk most módosítani 🙂
A functions.php fájlodba helyezd el a következő kódrészletet.
add_filter('the_content', 'auto_nofollow');
function auto_nofollow($content) {
//return stripslashes(wp_rel_nofollow($content));
return preg_replace_callback('/<a>]+/', 'auto_nofollow_callback', $content);
}
function auto_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;
}
Készen is vagyunk. 🙂