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?
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
echo
s as it occurs– think about template tags likethe_content
andthe_title
which don’t return strings. The justecho
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 orheader.php
andob_get_contents
(orob_get_clean
) at the end offooter.php
. But there are no hooks specifically at those locations. You should be able to capture most of the page withob_start
on awp_head
filter andob_get_contents
on awp_footer
filters. I’d have to play with things to dial it in. There may be a slightly better hook forob_start
. I doubt there is a better one forob_get_contents
.