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 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
.