0

我有以下问题:

我不希望 WP 将 wpautop 添加到所有页面,而只添加我需要的页面,所以我添加了这个:

function my_wpautop_correction() {
    if( is_page() ) {
        remove_filter( 'the_content', 'wpautop' );
        remove_filter( 'the_excerpt', 'wpautop' );      
    }
    if( is_page( array(79, 81) ) ) {
        add_filter( 'the_content', 'wpautop' );
        add_filter( 'the_excerpt', 'wpautop' );     
    }
}
add_action('pre_get_posts', 'my_wpautop_correction');

似乎工作正常,但我不确定它是否是编写该函数的最佳方式。我试过这个:

function my_wpautop_correction() {
    if( !( is_page(79) || is_page(81) ) ) {
        remove_filter( 'the_content', 'wpautop' );
        remove_filter( 'the_excerpt', 'wpautop' );      
    }
}
add_action('pre_get_posts', 'my_wpautop_correction');

但它不起作用,我做错了什么?我只想将 wpautop 添加到第 79 页和第 81 页。

4

1 回答 1

1

尝试这个:

function my_wpautop_correction() {
    if( !is_page(79) || !is_page(81) ) {
        remove_filter( 'the_content', 'wpautop' );
        remove_filter( 'the_excerpt', 'wpautop' );      
    }
}
add_action('pre_get_posts', 'my_wpautop_correction');
于 2013-06-21T16:26:43.747 回答