I am trying to use mustache within a wordpress application and modularize it. I would like to use mustache partials to inject the header and footer string into individual template files.

However, as soon as I call get_header / get_footer on the controller layer, the header and footer are echo'ed out immediately. What I am trying to do is just retrieve the markup from the header and footer and store it into a variable, for 'later' injection into the template is this possible?

Thanks in advance!

  • theses functions don't use filters. then to custom header and footer, you can create your own functions in your theme.
    – mmm
    Oct 23, 2017 at 19:05

1 Answer 1


Use an output buffer!

$header = ob_get_contents();

The header is now in $header and you can do with it as you please.

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.