Capture post content before page renders

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.

Read More

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

Related posts

1 comment

  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.

Comments are closed.