如何仅删除页面的自动段落格式,而不删除帖子(WordPress)

str*_*ive 4 php wordpress autoformatting

我已经熟悉了这个在WordPress中删除自动段落格式的小技巧:

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
Run Code Online (Sandbox Code Playgroud)

...但是在functions.php中添加它会删除整个站点的段落.这不是我想要的,因为客户端需要能够自己编辑(段落格式确实可以帮助他们在帖子上).

自动段落插入特别具有破坏性的是在客户端的主页上,其中有javascript片段.理想情况下,我想单独为此页面禁用自动p格式化,或者在必要时禁用所有页面,并单独保留帖子.

有任何想法吗?如果需要,我可以提供更多信息.

提前致谢!


编辑:

插件我试过:Php Exec,原始HTML,禁用WordPress Autop,PS禁用自动格式化,切换wpautop

rne*_*ius 10

您应该能够检查正在呈现的模板是否是使用is_page()的页面,然后可选地运行过滤器.我们挂钩'wp_head',以便我们可以在the_content调用之前运行检查.

例:

function remove_p_on_pages() {
    if ( is_page() ) {
        remove_filter( 'the_content', 'wpautop' );
        remove_filter( 'the_excerpt', 'wpautop' );
    }
}
add_action( 'wp_head', 'remove_p_on_pages' );
Run Code Online (Sandbox Code Playgroud)