最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Sharing Header Components Across Multisite

programmeradmin3浏览0评论

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/wp-content/themes/dokan/header.php";
?>

still no luck. Any tips will greatly be appreciated.

Cheers!

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/wp-content/themes/dokan/header.php";
?>

still no luck. Any tips will greatly be appreciated.

Cheers!

Share Improve this question edited Feb 11, 2016 at 8:57 dingo_d 1,9602 gold badges25 silver badges49 bronze badges asked Feb 11, 2016 at 7:08 Dave_ODave_O 551 gold badge2 silver badges9 bronze badges 6
  • So you try to use a dynamic menu of one site on another? Or is it just a template part? – fischi Commented Feb 11, 2016 at 7:36
  • It's a template part...but how can I make it dynamic though? – Dave_O Commented Feb 11, 2016 at 7:46
  • And you use different themes for those sites? – fischi Commented Feb 11, 2016 at 8:03
  • Yes. I am using different themes. – Dave_O Commented 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 Commented Feb 11, 2016 at 8:42
 |  Show 1 more comment

2 Answers 2

Reset to default 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
Description: Using the menu function across different themes in my network
Version:     1.0
Author:      Dave_O
Author URI:  http://wordpress.stackexchange/users/58774/dave-o
License:     GPL2
License URI: https://www.gnu/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.

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); 
发布评论

评论列表(0)

  1. 暂无评论