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