Using A Shared/Common Theme Across Multiple Sites

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?

Answers 1

  • 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.
    // Now restore the previous 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.

Related Questions