• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Embed custom header and footer


Active member

I would like to embed a custom header and footer. I would go about retrieving the data like this and putting it into a html file for caching.
$data = file_get_contents('http://site-with-header.com');

$doc = new DOMDocument();
$xpath = new DOMXpath($doc);
$head = $xpath->query("//head");
$header = $xpath->query("//header");
$footer = $xpath->query("//footer");

function domNodeList_to_string($DomNodeList) {
    $output = '';
    $doc = new DOMDocument;
    while ( $node = $DomNodeList->item($i) ) {     
        $domNode = $doc->importNode($node, true);
    $output = $doc->saveHTML();
    $output = print_r($output, 1);

    return $output;

echo domNodeList_to_string($head);
echo "<style type='text/css'> html {max-width: 960px; margin: auto;} </style>";
echo domNodeList_to_string($header);
// Content
echo domNodeList_to_string($footer);

Is there an easy way to include the output file as header/footer, so it is dynamically updated?