Php 拆下';p';标签v来自图像功能查询
我找到了一个解决方案,在创建一个只对一个图像有效的帖子时,从图像中删除p标签 对于它工作的图像,我查看了firebug,如下所示:Php 拆下';p';标签v来自图像功能查询,php,image,wordpress,Php,Image,Wordpress,我找到了一个解决方案,在创建一个只对一个图像有效的帖子时,从图像中删除p标签 对于它工作的图像,我查看了firebug,如下所示: <div class="entry-content"> <a href="http://localhost:8888/wordpress/wp-content/uploads/2013/02/img-1.png"> <img class="alignnone size-full wp-image-50" width="520" heig
<div class="entry-content">
<a href="http://localhost:8888/wordpress/wp-content/uploads/2013/02/img-1.png">
<img class="alignnone size-full wp-image-50" width="520" height="320" src="http://localhost:8888/wordpress/wp-content/uploads/2013/02/img-1.png" alt="img-1">
</a>
我只希望图像是我的文章的全部宽度,内容使用段落标记,正如我说的,它对我的第一张图像有效,但对任何其他图像都无效
感谢Wordpress在您通过内容过滤器运行时添加了标签。如果您不需要任何额外的标记,只需根本不通过任何过滤器运行它,或者在过滤器文档中查找您认为可以使用的过滤器 我认为你的解决方案是好的,但我认为你的正则表达式只是第一次出现。尝试对正则表达式使用
preg\u match\u all
你在使用微型微型微型计算机吗?不,我没有使用,这有助于解决问题吗?是的,你的权利只是第一次出现!我尝试使用preg_match_all函数,我的帖子内容消失,变成0。对于:'/\s*()?\s*()\s*()?\s*/iU','\1\2\3'。。。我需要删除哪些字符来测试是否为输入?我尝试过解决方案,但没有任何改变
<p>
<img class="alignnone size-full wp-image-50" width="520" height="320" src="http://localhost:8888/wordpress/wp-content/uploads/2013/02/img-1.png" alt="img-1">
<br>
Lorem ipsum dolo....
</p>
<?php
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');
?>
width:100%;
height:auto;
min-width:320px;
}