Same header/footer in Admin, across all network sites in multisite

Here’s what I did:

Inserted ob_start() and ob_get_clean(), at strategic places in header.php and footer.php within a child theme derived from my base site’s main theme.

<some header stuff> 
ob_start()  
<header html I want to reuse across network>
<?php $html = ob_get_clean(); echo $html; harvest_html($html, 'header'); ?>

The function harvest_html simply takes the string and writes it out to a file. I do the same thing for the footer. To keep overhead down, I only allow this function to execute when the user is_super_admin(). As long as the super admin logs in at least once, the header/footer will be harvested.

Then, in a simple plugin, I inject the harvested html into Admin by hooking to admin_head and in_admin_footer. Of course, any required CSS or JS needs to be enqueued at that time, too.

It works. Any user who is logged into their subdomain site and goes to any Admin page will get the header/footer of the base site, regardless of the theme they are currently using.

And, it’s relatively low maintenance since any changes made to header/footer for the base site will be automatically harvested.

I also handle pieces of header/footer that are dynamic (e.g. if some PHP echoes the user’s name or time of day, etc.) by parsing out function calls, identified by a special wrapper I put around them, then eval’ing them back in at the point they are injected in Admin.