2

I have a multi-site platform and I'm trying to share the menu that I have in main with other sites that are located in different folders.

This is the PHP tag in the main that pulls the menu which I also need in the header of other:

<?php dokan_header_user_menu(); ?>

I tried using it as it is in the header of /site2, and it didn't work. I also tried this:

<?php
    include $_SERVER['DOCUMENT_ROOT']."site.com/wp-content/themes/dokan/header.php";
?>

still no luck. Any tips will greatly be appreciated.

Cheers!

6
  • So you try to use a dynamic menu of one site on another? Or is it just a template part?
    – fischi
    Feb 11, 2016 at 7:36
  • It's a template part...but how can I make it dynamic though?
    – Dave_O
    Feb 11, 2016 at 7:46
  • And you use different themes for those sites?
    – fischi
    Feb 11, 2016 at 8:03
  • Yes. I am using different themes.
    – Dave_O
    Feb 11, 2016 at 8:40
  • Did you try outsourcing this function into a Plugin and so being able to use it on every site? Or copying it into the necessary themes?
    – fischi
    Feb 11, 2016 at 8:42

2 Answers 2

1

Outsource this function into a Plugin

If you want a specific function available across multiple themes, it is best to have it in a Plugin, and activate it networkwide.

Find the function

Locate the function in the theme where it is available. You now have two possibilities:

  • Delete the function from the current theme
  • Make a duplicate of this function to be used for other themes (recommended)

Create the plugin

Create a file in your plugins directory, f711-custom-menu-function.php or whatever you want your plugin to be called.

Inside this file you create the plugin header:

/*
Plugin Name: F711 Menu Function 
Plugin URI:  http://yourdomain.com
Description: Using the menu function across different themes in my network
Version:     1.0
Author:      Dave_O
Author URI:  http://wordpress.stackexchange.com/users/58774/dave-o
License:     GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Domain Path: /languages
Text Domain: f711-menu-function
*/

Now your Plugin is ready to use.

Populating your plugin

Copy the menu function of your theme, and give it a specific prefix, for example like this:

function f711_dokan_header_user_menu() {
    // insert your functionality from the original function here
}

Activate your plugin

This is selfexplanatory. Just be sure to activate it networkwide

Using it in different themes

Now you can call f711_dokan_header_user_menu() in all the themes available in your network, using the exact same function.

Cleanup

Take your original theme where the function comes from, and alter the header to use the new plugin function. Afterwards you can remove the old themespecific function to avoid redundancies.

7

That's an old question, here is another and easy solution for WORDPRESS MULTISITE MENU sharing across all network sites,

Not only menu you can use the same method to share anything other then widgets across all the network sites.

here is the solution : Edit your Header.php

//store the current blog_id - Use this function at the start of the function that you want to share

global $blog_id;
$current_blog_id = $blog_id;

//switch to the main blog which will have an id of 1
switch_to_blog(1);

//output the WordPress navigation menu - incase of menu-sharing use this

wp_nav_menu( 
   //add your arguments here
);

//switch back to the current blog being viewed - before ending of the function

switch_to_blog($current_blog_id); 

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.