I’m looking for a filter that provides the full page generated in WordPress – including the head section with meta tags, body, styling and dynamic content. the_content() and the_excerpt() do work only for the dynamic part and the request filter seems to work only for SQL queries (or not)?
I would like to filter some data in the entire page in all links or buttons. How can I do this?
3 s
You can use output buffering to accomplish this.
Add a high priority hook directly before the template is rendered:
add_action('template_redirect', 'foo_buffer_go', 0);
function foo_buffer_go(){
ob_start('foo_buffer_callback');
}
Add a shutdown hook with an extremely low priority.
add_action('shutdown', 'foo_buffer_stop', 1000);
function foo_buffer_stop(){
ob_end_flush();
}
Inside your callback, you manipulate the rendered HTML.
function foo_buffer_callback($buffer){
//Do something with the buffer (HTML)
return $buffer;
}
You may download this as a plugin here: http://3-3.me/B9lK
- Enable the plugin
- Visit the site and it will be rendered as “Foo Bar” which means you are capturing the entirety of the generated HTML