看下效果:
在这里,我们在之前go跳转的基础上进行修改,修改为:
//文章内外链添加go跳转
function the_content_nofollow($content){
preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
if($matches){
foreach($matches[2] as $val){
if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){
$content=str_replace("<a href=\"$val\"", "<i class='fa fa-external-link' style='color:#45b6f8' aria-hidden='true'></i><a href=\"".home_url()."/go/?url=$val\" ",$content);
}
}
}
return $content;
}
add_filter('the_content','the_content_nofollow',999);
保存即可,效果如下:
本文最后更新于2020年3月14日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!