I'm trying to mesh Mustache Templating Engine with WordPress. So far, I have been very successful using the_content as a filter to parse my template tags e.g. {{ something }}.

However, if let’s say, a developer hardcodes the template tags directly into the page template e.g. loop-page, the_content doesn’t capture the hardcoded tags.

Is there a filter that will allow me to capture the content of the whole page template including the content?

1 Answer 1


WordPress does not concatenate the entire page into a string before printing it which is what would have to happen to "capture" the whole page template. Much of the page echos as it occurs-- think about template tags like the_content and the_title which don't return strings. The just echo them.

You'd have to use output buffering to do this. That is pretty easy if you are writing the template-- ob_start at the beginning or header.php and ob_get_contents (or ob_get_clean) at the end of footer.php. But there are no hooks specifically at those locations. You should be able to capture most of the page with ob_start on a wp_head filter and ob_get_contents on a wp_footer filters. I'd have to play with things to dial it in. There may be a slightly better hook for ob_start. I doubt there is a better one for ob_get_contents.

  • Genius genius genius. I should have thought of this. Hooked it up in just a few line.
    – Aaron Lee
    Aug 11, 2013 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.