我正在尝试从wordpress中删除p标签,该标签会自动在图像中添加p标签。此外,我使用wordpress将图像居中,这样它就变成了这样的东西
所以我尝试添加此代码
function filter_ptags_on_images($content){
return preg_replace('/<p style=".*?">\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
这从p标记中删除了样式,它变成了这样的东西
<p><img src=...><p>
谁能帮助我如何仅从图像中删除p。
试试下面的代码:
function filter_ptags_on_images($content)
{
return preg_replace('/<p>(\s*)(<img .* \/>)(\s*)<\/p>/iU', '\2', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
或尝试修改您自己的代码:
function filter_ptags_on_images($content)
{
$content = preg_replace('/<p style=".*?">\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $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');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句