0

I have a plan to build a large local web directory. There will be around 6 sites under on multi network.

But it is hard to maintain 6 themes for each each site.

So what I want is, use Shared/Common Theme Across Multiple Sites. So I can use 1 navigation menu, one sidebar, etc. It is really easy for me. How can I do it?

  • Is that a multisite? If yes, subsites can share themes right. I feel like I'm missing something in here. If not a multisite, and you're gonna share the theme across different sites on different hosting, you might want to setup a git repo with a webhook. So that'd allow you to auto-update the themes across all sites when you update particular branch of the git repo to which the webhook is attached. I'll wait for clarifications from you to further elaborate this as answer – Kumar Jun 20 '18 at 6:28
  • @sven Is that a multisite? If yes, subsites can share themes right???? How to share? That is my problem. I want to use the one theme for all sites. – I am the Most Stupid Person Jun 20 '18 at 9:35
  • Network activate a theme, and activate same theme on all subsites, no? Or there is more to the theme. – Kumar Jun 20 '18 at 10:07
  • @sven Here I mean "Same" as not what you think. Sorry for my bad English. Same mean just one theme. Eg: If I add a widget to sidebar it should appear on all themes. If I add a code to single.php file it should appli for all sites – I am the Most Stupid Person Jun 20 '18 at 10:44
  • So maybe you're talking about the Menus and Sidebars and stuff like that, apart from the look of the sub sites. Because if you're adding Templates or making any changes to code to the theme that'd be available across all subsites anyway. Regarding the menus and sidebar widgets you can register them with theme but you'd need to manually assign to each site, that can't be automated easily. Maybe you can provide some sort of graphics to detail your question further. – Kumar Jun 25 '18 at 6:24
4
+50

If you're using multisite, you can upload a theme as the super admin and force enable it across the network. However, from what I've read in your question, it appears like you are trying to share contents across the network, not just the theme.

This can be somehow tricky. In such scenarios, you can use a core function called switch_to_blog(). This function allows you to switch to a specific blog while you are inside another blog.

You can use this function to fetch content from others blog. Set up your navigation menu in the first blog, and then retrieve it from your template:

// Switch to the main blog
switch_to_blog( $main_blog_id );

// Get the navigation menu. Don't forget to set the arguments,
// such as theme location.
wp_nav_menu();

// Now restore the previous blog
restore_current_blog();

The wp_nav_menu() function will now output the content from the main blog, for which you have set the proper menu.

However, you might end up having the permalinks from the main blog in this example. You can store the content of the menu in a variable using ob_start();, and then run a str_replace() on it to replace the old permalink with the new ones. Depending on different situations, you might need different approaches.

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.