Kava  |  Multipurpose WP Theme with Elementor Page Builder

My cart

Automatiser tous ses liens externes en “nofollow”

L’attribut nofollow (de l’anglais no follow, ne pas suivre) sert à spécifier que le lien en question ne doit pas être pris en compte par un programme (comme les robots des moteurs de recherches) lisant la page, ceci afin de ne pas augmenter le rang dans les moteurs de recherche du site internet vers lequel pointe le lien.
Pour pouvoir l’ajouter automatiquement à votre site wordpress, vous allez devoir modifier votre fichier functions.php en ajoutant ceci :

add_filter('the_content', 'my_nofollow');
add_filter('the_excerpt', 'my_nofollow');
function my_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;
}
Scroll to Top
Skip to content