How to get the entire page content in WordPress

It’s quite difficult to get the entire page content in a WordPress plugin. I eventually got this code to work. It requires two action handlers, one for the “send_headers” action just after the HTTP headers are sent and the HTML is just about to begin. The other handler is in the “shutdown” action, when the page is sent. By setting the priority to high on our action handler we can get in, grab the page and change it before it is returned. This gives the whole page from <HTML> to </HTML>.

function jw_callback($buffer) {
// Change contents of buffer here
// Just treat it like a string
return $buffer;
function jw_buffer_start() {
function jw_buffer_end() {
add_action(‘send_headers’, ‘jw_buffer_start’);
add_action(‘shutdown’, ‘jw_buffer_end’, 1);
Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter

Leave a Comment