Proper use of Output Buffer

No, you don’t need output buffering in this case. As a rule of thumb: Don’t use output buffering unless you really have to.

Just imagine what happens if someone else uses output buffering too from a plugin and it crosses with yours:

// plugin
ob_start();

// later, you in your theme
ob_start();

// you call a function where the plugin author hooked in to call:
print ob_get_clean();

// you call *your*:
return ob_get_clean();

// is is empty!

This is really hard to debug. Avoid it.


You don’t need a separate function to cover a plain do_action(). Just write do_action('roots_content_before'); in your theme.

Leave a Comment