Wordpress - 仅在一个页面上应用remove_filter

Ily*_*sis 6 wordpress

我在一个页面中插入多个页面(使用showmultiplepages插件),一个页面包含一个php文件(使用exec-php).我想仅为此包含的页面禁用过滤器.如果我加

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

在我的包含页面中,此页面后面的任何页面都没有过滤器.

是否有一些像"the_page"这样的标签,以便只有页面没有过滤器?

感谢帮助.

mro*_*ice 11

我知道这是一个老问题,但我想我会为那些想要在更广泛的意义上做这件事的人(例如不与插件输出结合)说明并且说你也可以将它添加到你的functions.php文件中:

add_filter('the_content', 'specific_no_wpautop', 9);
function specific_no_wpautop($content) {
    if (is_page('YOUR PAGE')) { // or whatever other condition you like
        remove_filter( 'the_content', 'wpautop' );
        return $content;
    } else {
        return $content;
    }
}
Run Code Online (Sandbox Code Playgroud)

  • @Devner`is_page()`现在支持一个数组,所以你可以把它全部一起滚动:`if(is_page(array('about','contact','management'))` (2认同)

Box*_*Box 5

我建议为"一个页面包含一个php文件(使用exec-php)"创建一个页面模板.然后在remove_filter(...)语句周围添加一个if语句.

if (!is_page_template('my-page.php'))
  remove_filter('the_content', 'wpautop');
Run Code Online (Sandbox Code Playgroud)

希望它有效.,P