I would like to apply these two functions that remove <p>
remove_filter('the_content', 'wpautop');
remove_filter( 'the_excerpt', 'wpautop' );
I would like it to only apply to wordpress pages. In the articles I would like to have them. How to do it?
I hope they can help me, I just start programming topics in wordpress.
Thank you.
I would like to apply these two functions that remove <p>
remove_filter('the_content', 'wpautop');
remove_filter( 'the_excerpt', 'wpautop' );
I would like it to only apply to wordpress pages. In the articles I would like to have them. How to do it?
I hope they can help me, I just start programming topics in wordpress.
Thank you.
Share Improve this question asked Oct 4, 2017 at 20:03 JhoedramJhoedram 1011 bronze badge1 Answer
Reset to default 1the_content filter apply to all posts which means pages and articles. What you can do is to add condition to its execution.
First you remove filter as you did
remove_filter('the_content', 'wpautop');
then you add another filter that will call the wpautop function depending on a test like this :
function my_the_content_filter($content) {
if(/* you test if it's an article or whatever you want*/)
$content = wpautop($content);
return $content;
}
add_filter( 'the_content', 'my_the_content_filter' );
like this you may control if the wpautop is called or not depending on your condition.
You do the same for the_excerpt