I’d like to remove auto formatting ‘wpautop’ from specific pages. Here is what I’ve got, but it doesn’t appear to work:
if ( is_page ( 'services' ) ) {
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
};
I am quite new to php, I have done some research to see how to write this statement, but I have had trouble finding an example that addresses my need. What would be the correct way to write this conditional statement?
You need to add your function in the
template_redirect
hook. You need to first wait for wordpress to finish loading pages before you can add your hook to removewpautop
, otherwise your hook will simply get run over. So your funtion will look like thisHere’s what I’ve found based off this question at Stack Overflow
You’ll have to remove wpautop entirely then add it back in whenever needed, which I agree in the linked comment, is unfortunate:
The question is old so you may want to watch this question for a day or two and see if somebody comes up with an improved answer.