0

I was kicking around a few ideas to accomplish this and came up with something a little strange...but it works.

I'm creating a theme for Admin, for my multisite network. The users will be exposed to both front-end and back-end pages when they are logged in, so it is important to me to have a consistent look as they traverse both spaces -- I don't want them dropping into the WP "plain old" Admin dashboard.

So, how do you get the base site's themed header/footer to show up on any networked site, when the user is logged in and in the back end?

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.