My whole theme uses remove_filter( 'the_content', 'wpautop' ); which strips the p tags and lines breaks from the output of the WYSIWYG. I have a custom post type events that I would like to bring back the auto p tags and br tags for, but JUST on that custom post type. Is there a way to make sure that filter doesn't get removed on events.


You can perform a conditional test against the current post type, like this:

if ( 'events' != get_post_type() ) {
    remove_filter( 'the_content', 'wpautop' );

The answer by @Manu will probably work for you, but it will fail if you have a query with events and posts as the post_type. Or two different queries on the same page. The solution is to check whether each post is of the events type and add or remove the filter accordingly.

add_action( 'the_post', 'wpse_257708_the_post', 10, 1 );
function wpse_257708_the_post( $post ) {
  if( 'events' === $post->post_type ) {
    add_filter( 'the_content', 'wpautop' );
  } else {
    remove_filter( 'the_content', 'wpautop' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.