plugin development - Filter on the_content ignores shortcodes

My function only affects the Page content and not the page content from the posts in page plugin which I call with a sho

My function only affects the Page content and not the page content from the posts in page plugin which I call with a shortcode in the page.

My plugin function

add_filter('the_content', 'modify_tables', 10, 1);

function modify_tables($content) {

    //modifications...

    return $content;
} // function modify_tables

My template code to ouput page

 while (have_posts()) : the_post();
      the_content(); 
 endwhile;

My function only affects the Page content and not the page content from the posts in page plugin which I call with a shortcode in the page.

My plugin function

add_filter('the_content', 'modify_tables', 10, 1);

function modify_tables($content) {

    //modifications...

    return $content;
} // function modify_tables

My template code to ouput page

 while (have_posts()) : the_post();
      the_content(); 
 endwhile;
Share Improve this question edited Nov 25, 2016 at 13:20 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Nov 25, 2016 at 11:30 jxwdjxwd 312 bronze badges 1
  • How does the page plugin output its content? This is probably something you will need to ask of whomever wrote that plugin. – Milo Commented Nov 25, 2016 at 11:37
Add a comment  | 

1 Answer 1

Reset to default 2

Unmodified do_shortcode is effectively a filter on the_content with priority 11. Your filter has priority 10. So it runs before the shortcode is evaluated and it won't affect the post you put inside your page with a shortcode.

Now, you would think that the filter should also be triggered when the post inside the page is retrieved. This, however, is not necessarily true. The filter is only triggered when the content is retrieved with the_content, not with get_the_content.

Depending on what your modifications are, you may get the desired result if you set the priority on your filter to 99 or so, forcing the shortcode to be evaluated before the filter is applied.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745179040a4615332.html

相关推荐

  • plugin development - Filter on the_content ignores shortcodes

    My function only affects the Page content and not the page content from the posts in page plugin which I call with a sho

    4小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信