Skip to content

Instantly share code, notes, and snippets.

@Kaiderella
Created April 12, 2017 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kaiderella/852fb93d528b8f0ea69aa9fc6a8f4243 to your computer and use it in GitHub Desktop.
Save Kaiderella/852fb93d528b8f0ea69aa9fc6a8f4243 to your computer and use it in GitHub Desktop.
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