WordPress自动给文章外链添加nofollow代码分享

Wordpress 2年前 (2021) acg
373 次浏览 0

nofollow的作用是什么?

nofollow在优化wordpress网站时很常用到,它的用处是告诉搜索引擎不要追踪此网页上的链接或不要追踪此特定链接,也就是不会导出权重到此链接。

nofollow对WordPress优化有着一定重要性。在文章内如果有外链地址,链接地址添加nofollw是很有必要的。

使用方法

//给文章外链添加nofollow
add_filter(‘the_content’,’web589_the_content_nofollow’,999);
function web589_the_content_nofollow($content){
preg_match_all(‘/href=”(.*?)” rel=”external nofollow” rel=”external nofollow” /’,$content,$matches);
if($matches){
foreach($matches[1] as $val){
if( strpos($val,home_url())===false ) $content=str_replace(“href=”$val””, “href=”$val” rel=”nofollow” “,$content);
}
}
return $content;
}

将上面代码添加到主题functions.php文件即可。

版权声明:acg 发表于 2021-12-02 20:00:54。
转载请注明:WordPress自动给文章外链添加nofollow代码分享 | ACGPK精选导航网

暂无评论

暂无评论...