最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Remove_filter ('the_content', 'wpautop') only pages

programmeradmin1浏览0评论

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 badge
Add a comment  | 

1 Answer 1

Reset to default 1

the_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

发布评论

评论列表(0)

  1. 暂无评论