阻止Wordpress在段落标记中包装图像

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了阻止Wordpress在段落标记中包装图像相关的知识,希望对你有一定的参考价值。

Wordpress by default wraps images in <p> tags, this kills that.
  1. // stop wordpress from wrapping images in <p> tags
  2. function filter_ptags_on_images($content)
  3. {
  4. // do a regular expression replace...
  5. // find all p tags that have just
  6. // <p>maybe some white space<img all stuff up to /> then maybe whitespace </p>
  7. // replace it with just the image tag...
  8. return preg_replace('/<p>s*(<a .*>)?s*(<img .* />)s*(</a>)?s*</p>/iU', '123', $content);
  9. }
  10.  
  11. // we want it to be run after the autop stuff... 10 is default.
  12. add_filter('the_content', 'filter_ptags_on_images');

以上是关于阻止Wordpress在段落标记中包装图像的主要内容,如果未能解决你的问题,请参考以下文章