如何解决wordpress自动加上p标签和br标签

如何解决wordpress自动加上p标签和br标签,第1张

在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加密地址》这篇文章。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/bake/11734633.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存