WordPress文章内容外链nofollow

WordPress文章内容如果经常插入外链,会将权重分散,可以加 nofollow 属性,禁止权重传递。WordPress主题 functions.php 插入:

add_filter('the_content','the_content_external',999);
function the_content_external($content){
	preg_match_all('/href="(.*?)"/',$content,$matches);
	if($matches){
		foreach($matches[1] as $val){
			if( strpos($val,$_SERVER['HTTP_HOST'])===false ) $content=str_replace("href=\"$val\"", "href=\"$val\" rel=\"external nofollow\" ",$content);
		}
	}
	return $content;
}

这个功能是全局的,即只要加入之后,single page 两个类型的文章内容外链都会加速nofollow。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注