admin管理员组文章数量:1122832
How can you ensure a given plugin is run last before the page finishes rendering?
Can it be ensured?
Specifically, I am writing a plugin that I want to post-process all content of a given post/page (after any formatting, extra links, ad injections, etc). The rest of the blog doesn't need to be processed - just posts & pages.
How can you ensure a given plugin is run last before the page finishes rendering?
Can it be ensured?
Specifically, I am writing a plugin that I want to post-process all content of a given post/page (after any formatting, extra links, ad injections, etc). The rest of the blog doesn't need to be processed - just posts & pages.
Share Improve this question edited Jul 24, 2017 at 20:19 warren asked Jul 24, 2017 at 19:20 warrenwarren 2812 silver badges17 bronze badges2 Answers
Reset to default 3You'll want to hook into "the_content" filter at a very high priority. Example:
function my_alter_the_content( $content ) {
if ( in_array( get_post_type(), array( 'post', 'page' ) ) ) {
// Do stuff here for posts and pages
}
return $content;
}
add_action( 'the_content', 'my_alter_the_content', PHP_INT_MAX );
Using the PHP_INT_MAX constant for the hook priority you can ensure it runs as last as possible (most plugins/themes will just use the default priority of 10).
The issue is when you say "after all ad injections...etc" that really depends how things are being added. Because if there are ads being added via javascript then of course the only way to override it would be via javascript.
Depending on what exactly you are trying to achieve, the shutdown
action might be the place to hook into as it
Fires just before PHP shuts down execution.
本文标签: orderEnsuring a plugin is loadedrun last
版权声明:本文标题:order - Ensuring a plugin is loadedrun last? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736297534a1930032.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论