开发者

Wordpress - Remove auto generated paragraphs for specific custom post type

开发者 https://www.devze.com 2023-04-11 11:18 出处:网络
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

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 wa开发者_如何学Pythony 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.


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号