Having trouble with a function in Wordpress

I have the following problem:

I don't want WP adding wpautop to all pages, but only the ones I need, so I added this:

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');

Seems to be working fine, but I am not sure if its the best way to write that function. I've tried this:

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');

But it doesnt work, what I am doing wrong? I want to add wpautop only to pages 79 and 81.

Upvotes: 0

Views: 99

Answers (1)

Noqomo
Noqomo

Reputation: 168

Try this:

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');

Upvotes: 1

Related Questions