在functions.php中添加
remove_filter ( 'the_content' , 'wpautop' )//移除文章p自动标签remove_filter ( 'the_excerpt' , 'wpautop' )//移除摘要p自动标签
remove_filter( 'comment_text', 'wpautop', 30 )//取消评论自动<p></p>标签
这个实现起来还是挺简单的,你可以使用以下代码试试:
//给外部链接加上nofollow标签add_filter('the_content','the_content_nofollow',999)
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("href=\"$val\"", "rel=\"nofollow\" href=\"$val\" ",$content)
}
}
}
return $content
}
不过现在大部分WordPress站点都是直接将外链变成内链来跳转的,具体可以参考本站分享的《实测WordPress外链转内链跳转地址为Base64加密地址》这篇文章。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)