Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress - Remove auto generated paragraphs for specific custom post type

Tags:

wordpress

I generated some custom post types in Wordpress where I need to add some html code to the post. The problem is that wordpress adds some nasty paragraphs all over my code and it`s breaking my lines. Is there any way to remove extra paragraphs generated by wordpress for this specific post type?

I use a custom loop for the posts and a single-posttype.php files so I have full control over the general output.

like image 422
Adrian Florescu Avatar asked Aug 10 '26 14:08

Adrian Florescu


1 Answers

you can remove the wpautop filter on the content by putting this into the functions.php of your theme by doing like this :

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);
}
like image 163
sbrajesh Avatar answered Aug 13 '26 18:08

sbrajesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!