douqin7086 2018-08-07 11:11
浏览 31

Wordpress返回preg_replace - 内容消失了

i have put this function in the functions.php theme file:

function filter_ptags_on_images($content){
   return preg_replace('​/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}

add_filter('the_content', 'filter_ptags_on_images');

After that the whole pages content are gone, i have deleted that function from functions.php but the content still not showing, any ideas why?

  • 写回答

1条回答 默认 最新

  • douyi7055 2018-08-07 12:17
    关注

    Try with this: <p>\s*(<a[^>]*>)?(<img[^>]+>)(<\/a>)?\s*<\/p>

    It will also work with images within <a> tags.

    Demo

    Explained:

    <p>               # p tag
      \s*             # 0 or more spaces
      (<a[^>]*>)?     # optional <a> tag:   (first capturing group)
                      #  it matches <a and then any non '>' character
                      #  repeated 0 or more times and then a '>'
                      #  (second capturing group)
      (<img[^>]+>)    # image tag
      (<\/a>)?        # optional closing </a> (third capturing group)
      \s*
    <\/p>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输