防止WordPress将换行符呈现为br标签

时间:2012-05-19 作者:LordZardeck

我厌倦了WordPress糟糕的HTML编辑器,决定用记事本++编写所有HTML,然后复制过来。但是,简单的换行符"\\n" 在html中通常被忽略的<br /> 标签。我已经禁用了可视化编辑器,所以我保存的所有内容都应该是显示的html。但事实并非如此。如何阻止wordpress转换html?

2 个回复
SO网友:jlengstorf

这是由filter 调用wpautop (声明于wp-includes/formatting.php, 第189行)。

您可以通过以下操作将其删除:

remove_filter(\'the_content\', \'wpautop\');

SO网友:Johnny Utahh

Toggle wpautop plugin.

这是我找到的最流行的解决方案,对我来说效果很好。以上插件页面显示了截至2016年5月21日的10000多个安装和100%的五星评级(其中23个)。

上述插件页面的描述:

Before WordPress displays a post\'s content, the content gets passed
through multiple filters to ensure that it safely appears how you
enter it within the editor.

One of these filters is wpautop, which replaces double line breaks
with <p> tags, and single line breaks with <br /> tags. However, this
filter sometimes causes issues when you are inputting a lot of HTML
markup in the post editor.

This plugin displays a checkbox in the publish meta box of the post
edit screen that disables the wpautop filter for that post.

Also adds a \'wpautop\', or \'no-wpautop\' class to the post_class filter
to help with CSS styling.
jlengstorf\'s answer 似乎不适用于我的WordPress 4。x安装。

结束

相关推荐