WordPress Snippets at WPcustoms

Remove wpautop only for custom post types

I struggled for a while to remove wpautop filter for content on specific custom post types. The regular conditional check with is_singular does not work due to a priority conflict. Thx to stackexchange I’ve found a nice solution which works like a charm. wpautop has default priority 10 so we set our modification function to 0.

 * Snippet Name: Remove wpautop only for custom post types
 * Snippet URL: https://wpcustoms.net/snippets/remove-wpautop-custom-post-types/
  function wpc_remove_autop_for_posttype( $content )
    // edit the post type here
    'portfolio' === get_post_type() && remove_filter( 'the_content', 'wpautop' );
    return $content;
add_filter( 'the_content', 'wpc_remove_autop_for_posttype', 0 );