admin管理员组

文章数量:1414628

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.

本文标签: plugin developmentFilter on thecontent ignores shortcodes