Welcome to Dagon Design. In addition to free scripts, WordPress plugins, and articles, we offer a variety of services including custom theme design, plugin creation, and PHP scripting. Contact me for more information.

Updated Thursday, February 19th, 2009 at 2:14pm

WordPress Hook for Entire Page Using Output Buffering

The WordPress plugin API provides a large number of action and filter hooks to make plugin creation easier. While the provided hooks cover just about everything you would need for plugin development, it can occasionally be useful to have a hook that can process the entire html output of WordPress. This article describes a method that can be used to create a ‘virtual’ hook which allows processing of everything between the end of the header section, and the footer of the theme, using the output buffering feature of PHP.

Plugin Code

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');


This plugin code registers two actions – buffer_start and buffer_end.

buffer_start is executed at the end of the header section of the html. The parameter, the callback function, is called at the end of the output buffering. This occurs at the footer of the page, when the second registered action, buffer_end, executes.

The callback function is where you add your code to change the value of the output (the $buffer variable). Then you simply return the modified code and the page will be displayed.


Be sure to use unique function names for buffer_start, buffer_end, and callback, so they do not conflict with other functions you may have in plugins.

For more information on output buffering in PHP, visit the PHP page for the ob_start() function.

  If you have found this page useful, please consider donating. Thanks!

Pages: [5] 4 3 2 1 » Show All

  1. Oh I have never heard about these plugins, let’s give it a try. Thank you for sharing!

  2. 70

    You have really dodgy spam in your comments. Search them for adalagu

  3. Nice blog brot

  4. Nice picture brother

  5. Nice picture brothe
    <a rel="dofollow" href="http://adalagu.xyz">download lagu terbaru</a>

  6. I needs to spend a while learning much more or working out more. Thank you for wonderful information I was for this information for my mission

  7. Cok guzel – Very Nice Content … :)

  8. Very Nice Content … :)

  9. Very Nice Content :)

  10. Terima kasih banyak

  11. yuk ah kunjungi website ane di

    Mesin Bakso

Pages: [5] 4 3 2 1 » Show All

Leave a Comment

Before you comment: If you are having an issue with a script, please make sure you have read the entire article. Also, please read through the comments because most common issues have already been discussed many times. Thanks.

Be sure to wrap all code in <code></code> tags.