0

I am looking for a solution to reuse the header and footer navigation links (with style, of course) in one of my WordPress website for several other WordPress sites.

Please note that I'm trying to share header and footer among WordPress sites, not from WordPress site to a PHP page. The sites I'm referring to are on the same server. I have the following directory structure:

example.com/ #main site is here
   some-other-site/
      wp-admin/
      wp-content/
      wp-include/
      ...
   wp-admin/
   wp-content/
   wp-include/
   ...

I would really appreciate some direction on how to achieve this goals and best practices, if possible since I am still new to WordPress. I have a few ideas in mind but I am not sure which one is best programming practice or how much effort each approach requires (for cost benefit analysis)

1) Write a custom get_header() function in the main site's functions.php to allow extraction of navigation links file_get_contents() to get the navigation links from wp-content/themes/my-theme/inc/footer.php in some-other-site/ I use

define('WP_USE_THEMES', false);
require($_SERVER['DOCUMENT_ROOT'] . '/wp-blog-header.php');

Currently, I get "<a href="&lt;?php bloginfo('siteurl'); ?&gt;/articles/category/editorial_team">Background</a>" as output so it doesn't work for me yet.

I found one similar topic but the question is a bit unclear to me and the solution of using absolute urls is not a good practice, I was told.

2) Expose those navigation links as web service. I have a feeling that web service is not even relevant here but I still put it here just in case.

3) Use Multisite settings or create a network for all my WordPress sites. While this appears to be the best way, it seems quite complicated and there are actually issues with my main site being setup in a network currently. I doubt it's necessary to got through this complication to achieve my goal.

As far as I know, sites in WordPress network shares certain databases and therefore I'm so afraid of losing some or whole of the huge data in my main site.

It would definitely be relevant to point out the best practices in sharing CSS stylesheets and Javascripts file among WordPress sits as well, if you are kind enough :)

Sorry my long post. Thank you very much! Eric P.S.: Sorry for duplicating this post from StackOverflow.com. I have found the answers for all of my WordPress related questions on StackOverflow.com so far so I just don't know which is the more appropriate place to ask. Please advise if I need to merge the 2 topics on 2 sites. Thanks!

2 Answers 2

0

I would think that your best bet is option 3 (multisite) if possible. Once you've got your network of sites set up you can then specify which menu to use as described here.

Doing the other solutions (a more rough and ready 'hardcoded' approach) will almost certainly give you headaches in the future. Having multisite set up also has advantages such as ease of updating and maintenance of user base.

You're right that if you use a multisite setup, all sites use one database. You shouldn't lose any data in the handover, but you should definitely do a complete backup first in case. If you're worried, do a dry run by setting up a testing environment and exporting / importing the data using Tools > Export / Import.

3
  • Thank you. It looks like WordPress multisite is the right thing I have to do for long term benefits it brings. I'm just crossing my fingers that the export & import process will go smoothly as my site has a lot of data and it's already in a buggy multisite setup (which I don't know why I rather start from scratch and import old data)
    – ericn
    Sep 19, 2011 at 9:31
  • If you're worried, you could do a dry run first before touching anything on the live sites. For example, do it on your local machine using XAMPP
    – ewels
    Sep 22, 2011 at 13:35
  • sure, tallphil, I'm setting everything up in my local environment right now. Thanks for commeting
    – ericn
    Sep 28, 2011 at 5:20
0

I would certainly suggest a multisite approach too.

Not sure if I am misinterpreting what you are asking for (and not sure if best practice) but if you are going to be using the same header/footer on all sites and they are all going to look the same (but just have different content in the middle) then it might be worth setting them all to use the same theme?

p/s: All sites on the multisite, as tallphil said, uses one database - the numbering of the (key) tables change for each site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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