我有以下代码,这些代码将<p>标记放回我的Wordpress帖子中的段落中。(我删除了图像,并在以后放置它们,使用它仅放置文本)
<p>
<?php
$content = preg_replace('/(<img [^>]*>)/', '', get_the_content());
$content = wpautop($content); // Add paragraph-tags
$content = str_replace('<p></p>', '', $content); // remove empty paragraphs
echo $content;
?>
</p>
它可以正常工作,然后将我的段落再次放入p标记中,但是会在我的实际段落之间输出空的<p> </ / p>标记。我想摆脱这些空的段落标签
您只是覆盖了变量
尝试将此操作(注意.=
代替=
).=
,而不是覆盖该变量。
$content = preg_replace('/(<img [^>]*>)/', '', get_the_content());
$content .= wpautop($content); // Add paragraph-tags
$content .= str_replace('<p></p>', '', $content); // remove empty paragraphs
echo $content;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句