will-ashworth
5/2/2019 - 4:43 AM

Modify final output in WordPress

Sometimes it's necessary to adjust final output. Here's how.

<?php
function callback($buffer) {
  // modify buffer here, and then return the updated code
  return $buffer;
}

function buffer_start() { ob_start("callback"); }

function buffer_end() { ob_end_flush(); }

add_action('wp_head', 'buffer_start');
add_action('wp_footer', 'buffer_end');