"philosophy_text“是用ACF plugin (高级自定义字段)创建的textarea字段。当在p标记中使用the_field()显示此字段时,产生的标记会被两个临时创建的额外p元素混淆。不幸的是,这并不仅仅发生在这个特定的插件上。过去,我多次在默认的WordPress函数the_content()中遇到这个恼人的问题:
我的代码:
<p class="philosophy__story">
<?php if (get_field('philosophy_text')) the_field('philosophy_text'); ?>
</p>由此产生的标记:
<p class="philosophy__story"></p>
<p>Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Some more text that make sense for us to have, short not to much though.</p>
<p></p>这是一个WordPress错误吗?有什么解决办法吗?
发布于 2017-04-05 20:39:45
高级自定义字段的textarea字段具有如何处理呈现新行的设置。默认情况下,该设置设置为将内容包装在<p>标记中。
您可以将其更改为打印换行符的<br>标记,不要对换行符执行任何操作,也可以在PHP代码中删除包装<p>元素,并允许ACF为您完成此操作。

发布于 2017-04-05 20:38:06
编辑中的textarea字段,@leland的答案是正确的。如果有人在寻找其他领域的答案,我会留下这个。
它实际上是一个特性,而不是一个bug。但是,如果您不喜欢这个功能,可以禁用它。
在ACF之外,这将通过以下方式进行:
remove_filter ('the_content', 'wpautop');但是ACF使用一个名为“acf_the_content”的自定义筛选器,因此在您的functions.php文件中尝试如下:
remove_filter ('acf_the_content', 'wpautop');这个答案几乎是从对ACF的支持中复制出来的。
https://support.advancedcustomfields.com/forums/topic/removing-paragraph-tags-from-wysiwyg-fields/
https://stackoverflow.com/questions/43240894
复制相似问题