[短代码]为文章中链接添加nofollow


为自己文章中的所有外链自动加nofollow防止权重流失。

//给文章外链添加nofollow
add_filter('the_content','web589_the_content_nofollow',999);
function web589_the_content_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 noopener nofollow\" ",$content);
}
}
return $content;
}

 

版权声明:
作者:月宅
链接:https://blog.moetwo.com/7254.html
来源:月宅酱的博客
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>