我有以下问题:
我不希望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');
但它不工作,我做错了什么?我想只在第79页和第81页添加wpautop
试试这个:
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');