Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to try and remove automatic p tag and br tag addition for my custom post type.

It looks like

remove_filter( 'the_content', 'wpautop' );

will do this, but how would I make the change only for my chosen post type I've tried writing a function for this, but it doesnt seem to work:

function remove_tags() {
    global $post_type;

    if ('client' == $post_type) {
        remove_filter( 'the_content', 'wpautop' );
    }
}
share|improve this question
    
Where are you putting these functions? –  s_ha_dum Jan 23 '13 at 23:15
    
in my custom post type plugin file –  user319940 Jan 23 '13 at 23:16
add comment

2 Answers 2

Hook into the_content before the wpautop filter has been called, check the post type, and remove the wpautop filter, which is added in wp-includes/default-filters.php with the default priority 10:

add_filter( 'the_content', 'wpse_82860_remove_autop_for_posttype', 0 );

function wpse_82860_remove_autop_for_posttype( $content )
{
    # edit the post type here
    'post' === get_post_type() && remove_filter( 'the_content', 'wpautop' );
    return $content;
}
share|improve this answer
add comment
up vote 1 down vote accepted
remove_filter('the_content','wpautop');

//decide when you want to apply the auto paragraph

add_filter('the_content','my_custom_formatting');

function my_custom_formatting($content){
if(get_post_type()=='my_custom_post') //if it does not work, you may want to pass the current post object to get_post_type
    return $content;//no autop
else
 return wpautop($content);
}

found this code on stackoverflow - looks to do the trick.

share|improve this answer
    
+1 for finding your own answer :) Please post the URL for the question where you found the code though. –  s_ha_dum Jan 23 '13 at 23:29
    
original can be found here stackoverflow.com/questions/7697465/… –  user319940 Jan 23 '13 at 23:33
    
This will break when another plugin wants to do the same for another custom post type. –  toscho Jan 24 '13 at 3:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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