Wordpress-仅在一页上应用移除过滤器

Wordpress-仅在一页上应用移除过滤器,wordpress,Wordpress,我在一个页面中插入多个页面(使用showmultiplepages插件),一个页面包含一个php文件(使用exec php)。 我只想禁用此包含页面的筛选器。如果我加上 remove_filter( 'the_content', 'wpautop' ); 对于我的包含页面,在此页面之后提交的任何页面都不会有过滤器 是否有像“theu页面”这样的标签,这样只有页面才没有过滤器 谢谢您的帮助。我建议为“一个页面包含一个php文件(使用exec php)”,创建一个页面模板。然后在remove_fi

我在一个页面中插入多个页面(使用showmultiplepages插件),一个页面包含一个php文件(使用exec php)。 我只想禁用此包含页面的筛选器。如果我加上

remove_filter( 'the_content', 'wpautop' );
对于我的包含页面,在此页面之后提交的任何页面都不会有过滤器

是否有像“theu页面”这样的标签,这样只有页面才没有过滤器


谢谢您的帮助。

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

if (!is_page_template('my-page.php'))
  remove_filter('the_content', 'wpautop');

希望它能奏效;P

我知道这是一个老问题,但我想我会插话给那些希望在更一般意义上这样做的人(例如,不与插件输出结合使用),并说您也可以将其添加到

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;
    }
}
不起作用

add_filter('the_content', 'specific_no_wpautop', 9);
function specific_no_wpautop($content) {
    global $post;
    if (is_single('5136') || ('3820')){ // or whatever other condition you like
        remove_filter( 'the_content', 'wpautop' );
        return $content;
    } else {
        return $content;
    }
}

像mroncetwice一样,我也意识到这是一个老问题;然而,当我看到他的时候,我来到这条线寻找答案。我决定改进它(就适合我自己的情况而言),并分享结果,希望它也能帮助其他人


默认情况下打开或关闭wpautop,并列出所有异常:

/**
 * Allow or remove wpautop based on criteria
 */
function conditional_wpautop($content) {
    // true  = wpautop is  ON  unless any exceptions are met
    // false = wpautop is  OFF unless any exceptions are met
    $wpautop_on_by_default = true;

    // List exceptions here (each exception should either return true or false)
    $exceptions = array(
        is_page_template('page-example-template.php'),
        is_page('example-page'),
    );

    // Checks to see if any exceptions are met // Returns true or false
    $exception_is_met = in_array(true, $exceptions);

    // Returns the content
    if ($wpautop_on_by_default==$exception_is_met) {
        remove_filter('the_content','wpautop');
        return $content;
    } else {
        return $content;
    }
}
add_filter('the_content', 'conditional_wpautop', 9);

我的荣幸。您可能需要将is_page_template()更改为其他条件标记。我想知道我的想法是否有效。谢谢,嗯。。。答案或问题,或者只是复制另一个答案?这就是为什么该选项不适用于多个页面的问题?如果(is_sangle('5136')| |('3820'))好吧,如果你有问题,请发一个。。。(这是答案部分:-)对不起,我没有时间用同样的方式写。通过在每个页面中添加一个新函数,问题得以解决。谢谢。您不需要
global$post
mmm,你是对的@henrywright-使用_content()模板标记需要在循环中使用它,因此,$post变量确实已经可用。答案编辑好了,这很有效。为了在您的网站的“关于”页面上使用此选项,您可以将检查写为
if(is_page('About'))
。使用
|
运算符附加条件以包含更多页面。@Devner
is|u page()
现在支持一个数组,因此您可以将其全部放在一个数组中:
if(is|u page(数组('about','contact','management'))
@rnevius这太酷了&甚至更好。感谢分享。我期待在下一个项目中使用它。+1仅此更新:)