Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nofollow tất cả external links
//* Add rel nofollow to all external links
function wp_nofollow($content)
{
return preg_replace_callback('/<a[^>]+/', 'wp_nofollow_callback', $content);
}
function wp_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;
}
add_filter('the_content', 'wp_nofollow');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.