Borek的答案不适用于我的用例,即编写原始HTML。
为此,我使用了Code Snippets 插件(允许您轻松添加运行的任意PHP代码段),以创建[html][/html]
短代码。这个短代码的酷之处在于它与toggle-wpautop 允许您禁用自动插入的插件<br>
和<p>
整个帖子上的标签。您可以使用任意一种,mix&;火柴
function html_shorttag_filter($content) {
// Based on: https://wordpress.org/plugins/lct-temporary-wpautop-disable-shortcode/
$new_content = \'\';
$pieces = preg_split(\'/(\\[html\\].*?\\[\\/html\\])/is\', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
// don\'t interfere with plugin that disables wpautop on the entire page
// see: https://plugins.svn.wordpress.org/toggle-wpautop/tags/1.2.2/toggle-wpautop.php
$autop_disabled = get_post_meta(get_the_ID(), \'_lp_disable_wpautop\', true);
foreach ($pieces as $piece) {
if (preg_match( \'/\\[html\\](.*?)\\[\\/html\\]/is\', $piece, $matches)) {
$new_content .= $matches[1];
} else {
$new_content .= $autop_disabled ? $piece : wpautop($piece);
}
}
// remove the wpautop filter, but only do it if the other plugin won\'t do it for us
if (!$autop_disabled) {
remove_filter(\'the_content\', \'wpautop\');
remove_filter(\'the_excerpt\', \'wpautop\');
}
return $new_content;
}
// idea to use 9 is from: https://plugins.svn.wordpress.org/wpautop-control/trunk/wpautop-control.php
add_filter(\'the_content\', \'html_shorttag_filter\', 9);
add_filter(\'the_excerpt\', \'html_shorttag_filter\', 9);