You’ve created a navigation menu on the main site. Let’s see how to make it work across all websites of the network.
How to make sub-sites which use the same theme inherit navigation menu from the main site?
I’ll use Twenty Seventeen Theme Â as an example, but this can be done for any other theme and any other template file as well.
Here is the defaultÂ
if ( has_nav_menu( 'social' ) ) : is looking for the navigation menu in the current site. To make it look for the menu in the main site all we need to do is to point WordPress to that site. We’ll do that using
//Get $blog_id to remember where we currently are
$current_blog_id = $blog_id;
//switch to the main site which has id of 1
//Nothing new here: we are just outputting navigation menu (from main blog now)
if ( has_nav_menu( ‘social’ ) ) :
Make navigation menu displayed on the sub-sites even if they use the theme different from the main site
This is how you can get the navigation menu from the main site displayed in any place of any theme of your network
Just keep in mind this will give you raw menu from database without any styling, you’ll have to add styles to your style.css of the current theme. In case you need the same styling for this navigation menu through all themes in your network, you might consider adding css file to the
mu-plugins directory to make load everywhere in your network regardless the theme.
Make the combination of navigation menus from different sites of the network
Actually, you can get navigation menu from any sub-site of the network just replacing 1 with ID of that very blog in
switch_to_blog(1); line. You can put them together and make really aggregated navigation menu.
WordPress Multisite global menu is a short way to make a strong connection between sites in your network which may become an effective internal link building tool as well.