用代码为wordpress页面及文章的连结自动加上nofollow,优化wordpress的seo
现在我们也要让页面具有这样的功能!
可以将代码贴入主题的functions.php
[cc lang="php"]//用代码为wordpress页面及文章的连结自动加上nofollow,优化wordpress的seo add_filter( 'the_content', 'cn_nf_url_parse'); function cn_nf_url_parse( $content ) { $regexp = "
]*href=("??)([^" >]*?)\1[^XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 1 ) $noFollow .= ' target="_blank" '; $pattern = '/rels*=s*"s*[n|d]ofollows*"/'; preg_match($ pattern, $tag2, $match, PREG_OFFSET_CAPTURE); if( count($match)< 1 )
$noFollow .= ' rel="nofollow" ';
$pos = strpos($url,$srcUrl);
if ($pos === false) {
$tag = rtrim ($tag,'>');
$tag .= $noFollow.'>';
$content = str_replace($tag2,$tag,$content);
}
}
}
}
$content = str_replace(']]>', ']]>', $content); return $content; }[/cc]