Archived

This topic is now archived and is closed to further replies.

  • 0

Multisite - Serving The Same Header And Footer Content On Multiple Child Themes?


Question

Posted · Report post

I have a multisite wordpress install using the Pagelines Framework theme. I have created two child themes for Pagelines -- one for the parent site and one for the sub sites. I am trying to get the sub sites to display the same header and footer content as the parent site. Because Pagelines populates it's header and footer content dynamically based on Pagelines settings for each site (and not hard coded), is there any way to serve the header and footer content from the parent site to all of the sub sites?

Anyone got an idea on how to accomplish this?

The parent site (using pagelines child theme: kid 2 kid) is here: http://updated-kid2kid.com
the test subsite (using pagelines child theme: kid 2 kid stores) is here: http://updated-kid2kid.com/test

My logic is that there might be some code I can add to a header.php file for the /test child theme that will display the header content from the parent site... Open to ideas!

Thanks!

1 person likes this

Share this post


Link to post
Share on other sites

10 answers to this question

Posted · Report post

My recommendation would be that, instead of coding into a header.php file and possibly messing up Pagelines, use the appropriate hooks:

 

pagelines_register_hook('pagelines_before_site');
pagelines_register_hook('pagelines_after_footer');

To use these, you would do something like this:

add_action('pagelines_after_footer','myfunct');
function myfunct(){
	echo '<h1>Test</h1>';
}

That would output an <h1> with the word "Test" in it at the very bottom of the website. Then you would just change the 'pagelines_after_footer' and 'myfunct' to reflect the pagelines_before_site hook and whatever you wanted for the function name. This would allow you to have whatever is included in the functions automatically included in the header/footer of every site.

Share this post


Link to post
Share on other sites

Posted · Report post

Thanks guys!  It is now obvious there are a number of ways to hard code a Header and Footer on all the subsites -- If I am understanding correctly, all of these ways require me to hard code the header and footer. That would be all fine and dandy except - I am wondering if there is a solution that will pulll the header and footer content from the parent site dynamically.  The only reason I am wondering this is because the menu on the parent site (which is located in the header and footer) will most likely change regularly.  I would love for when the client makes those updates to the menu (from the parent site), the menu options in the header and footer on all the subsites will change dynamically as well.  I am trying to make the site as turn key as possible for the client and would like the navigation menu to be editable via the admin panel of the parent site.

 

If I am understanding correctly:

 

dokether - I think I am following, but it seems this solution I would have to hard code the header and footer right? Is there any way to reference the menu navigations from the parent site dynamically

 

catrina - tried out the plugin.  It's pretty cool but unfortunately, I have to hard code HTML for the header and footer still... Is there any way to reference the menu navigations from the parent site dynamically

 

Simon_P - I have never heard of mu-plugins... not sure how to implement the header and footer from the parent site on all the subsites using Must Use.  Can you clarify?

 

I think we are close... I feel like there has to be a way to do this, but am just not well enough versed in all that is wordpress :)

Share this post


Link to post
Share on other sites

Posted · Report post

This would insert a comment into the <head> of every site.

add_action( 'wp_head', 'my_header' );
function my_header() {
    echo '<!-- this is on all sites in the <head> -->';
}

Share this post


Link to post
Share on other sites

Posted · Report post

Simon_P - I could totally add this code in the the functions.php file of the child theme for all the subsites, but I would still have to hard code the menu in the header right?  Is there some code that I can use that will serve up the navigation menu from the parent site OR do I just have to hard code it and manually change the code in this function every time there is a change in the menu (which is what I am trying to avoid)? I am trying to make the site as turn key as possible for the client and would like it when ever the navigation menu is changed (via the wordpress admin panel on the parent site) those updates are served up dynamically on all the subsites (without me having to change the code every time).

 

Is there a solution for this?

Share this post


Link to post
Share on other sites

Posted · Report post

You want the menu the same on all subsites? How will a user navigate from inside the subsite if the menu links are all for the parent site?

Share this post


Link to post
Share on other sites

Posted · Report post

Yeah, so it will display the header and footer of the parent site before and after the subsite content.  I still want the subsite to have it's own menu, it will just not be the primary menu... does that make sense? Here is a screen cap to illustrate what I hope to accomplish:

 

WebsiteSUBSITES1.jpg

Share this post


Link to post
Share on other sites

Posted · Report post

Hi dokether,

 

I thought about hard coding hooks right into the functions.php file for the child theme, but I would like the content in the header and footer to populate dynamically -- so if the admin changes the header (with the navigation and branding) on the parent site, that change would reflect on all the sub sites dynamically.  I don't want to hard code in the header and footer on the base theme for the subsites because I am trying to make this site as turn key as possible for the client when I deliver it.

 

I am using child theme for the parent theme and a separate child theme for the subsites.  

 

Catrina, I will try out that plugin and respond with the outcome.  Thanks for the heads up about it.  

 

Thanks for the response guys!

Share this post


Link to post
Share on other sites

Posted · Report post

Well, the thing is that you can still do that the way I shared. Instead of putting your code into the function() though, you could simply do an include.

 

Let's say you have your header and footer in a directory structure like this:

wp-content
   plugins
   themes
      global_header.php
      global_footer.php
      pagelines *THEME*
      child1 *THEME*
      child2 *THEME*
      child3 *THEME*

 

Then you could have your hook called in your functions.php for your child themes as such:

add_action('pagelines_after_footer','myfunct');
function myfunct(){
	include "../global_footer.php";
}

I haven't tested it out, but that should work. Then you would be able to edit just global_footer and global_header php files anytime you want to update the header/footer.

Share this post


Link to post
Share on other sites

Posted · Report post

There is of course a far easier way ;)

 

Wordpress has a secret folder called mu-plugins, if you add it to wp-content and put a php file in there wordpress will auto run it, no need to activate and it runs on every site! mu is Must Use.

 

So add your footer action in there and it'll run on every site.

Share this post


Link to post
Share on other sites