网站内容通常会有很多外部链接,如果每个都手动修改nofollow标签很麻烦,这里分享给大家这篇利用正则表达式自动判断链接是否为外链,如果是外部链接就自动加上nofollow标签的教程。这样可以很好的优化网站链接,减少网站传递权重,也无需手动添加修改。
function tin_seo_wl( $content ) {
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>";
if(preg_match_all("/$regexp/siU", $content, $matches, PREG_SET_ORDER)) {
if( !empty($matches) ) {
$srcUrl = get_option('siteurl');
for ($i=0; $i < count($matches); $i++)
{
$tag = $matches[$i][0];
$tag2 = $matches[$i][0];
$url = $matches[$i][0];
$noFollow = '';
$pattern = '/target\s*=\s*"\s*_blank\s*"/';
preg_match($pattern,