WordPress链接优化:给外链、分类和标签加上external nofollow

admin WordPress教程 0

对于网站引用了太多的外部连接,权重会受影响,很多站长都比较在意这个细节,下面给出几种方案:

站外连接添加nofollow

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

分类添加nofollow

function crunchify_nofollow_cat($text) {
global $post;
        if( in_category(1) ) { // YOUR CATEGORY ID HERE 可变
                $text = stripslashes(wp_rel_nofollow($text));
        }
        return $text;
}
add_filter('the_content', 'crunchify_nofollow_cat');

标签添加nofollow

function nofollow_cat_posts($text) {
global $post;
        if( has_tag(1) ) { // SET TAG ID HERE 可变
                $text = stripslashes(wp_rel_nofollow($text));
        }
        return $text;
}
add_filter('the_content', 'nofollow_cat_posts');

放functions.php里,效果就是给连接加上了rel="nofollow"。

下载地址

免责声明

本站提供的一切软件、教程和内容信息仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑或手机中彻底删除上述内容。如果您喜欢该程序,请支持正版,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。敬请谅解!

您需要 登录账户 后才能发表评论

欢迎 你 发表评论: