Global Main Nav for Multisite
-
Okay,
I’m only using the Graphene theme on every sub-site (sub-directories, 20 of them). Actually it’s the Graphene child theme which is used on every site.
I would like to be able to create a global main nav menu in the main site, which will be replicated in every subsite. This global menu will never change no matter which subsite is visited.
Then, each subsite will also have a secondary menu which is unique to each subsite.
So, is there a way to use a child theme function to “force” a global main nav menu?
Okay, I have it working by editing
header.phpin the core. But, I’d prefer not to do it that way. Here is the code I changed:<div id="header-menu-wrap" class="clearfix">
<?php
/* Header menu */
$args = array(
'container' => '',
'menu_id' => 'header-menu',
'menu_class' => graphene_get_menu_class( 'menu clearfix' ),
'fallback_cb' => 'graphene_default_menu',
'depth' => 5,
'theme_location' => 'Header Menu',
);
if ( ! $graphene_settings['disable_menu_desc'] )
$args = array_merge( $args, array( 'walker' => new Graphene_Description_Walker() ) );
/******* ADDED BY JOSH LOBE *******/
//store the current blog_id being viewed
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
/******* END ADDED BY JOSH LOBE *******/
wp_nav_menu( apply_filters( 'graphene_header_menu_args', $args ) ); ?>
<?php /******* ADDED BY JOSH LOBE *******/
//switch back to the current blog being viewed
switch_to_blog($current_blog_id);
/******* END ADDED BY JOSH LOBE *******/ ?>
<div class="clear"></div>Admin
Not sure if this will work, but try:
function sync_main_site_nav( $args ){
if ( $args['theme_location'] == 'Header Menu' ) {
global $blog_id, $current_blog_id;
$current_blog_id = $blog_id;
switch_to_blog(1);
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'sync_main_site_nav' );
function reset_site_nav( $nav_menu, $args ){
if ( $args['theme_location'] == 'Header Menu' ) {
global $current_blog_id;
switch_to_blog( $current_blog_id );
}
return $nav_menu;
}
add_filter( 'wp_nav_menu', 'reset_site_nav', 10, 2 );Fatal error: Cannot use object of type stdClass as array in /home/frcdecom/public_html/wp-content/themes/graphene-child/functions.php on line 41
EDIT: This is line 41
if ( $args['theme_location'] == 'Header Menu' ) {Admin
Try this:
function sync_main_site_nav( $args ){
if ( $args->theme_location == 'Header Menu' ) {
global $blog_id, $current_blog_id;
$current_blog_id = $blog_id;
switch_to_blog(1);
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'sync_main_site_nav' );
function reset_site_nav( $nav_menu, $args ){
if ( $args->theme_location == 'Header Menu' ) {
global $current_blog_id;
switch_to_blog( $current_blog_id );
}
return $nav_menu;
}
add_filter( 'wp_nav_menu', 'reset_site_nav', 10, 2 );Okay, that got rid of the error… but now the normal subsite main nav menus are loading… not the global.
Should I un-assign any menu I have set as the header menu in each subsite?
Admin
Quote:Should I un-assign any menu I have set as the header menu in each subsite?No, if it works this shouldn’t have mattered. I’ll keep an eye out for any other possible solution.
No worries at all. I tested a little also and couldn’t quite get it.
This is the first time I’ve used your theme on a paid job for a client, so I told the college to include a donation to the author in my invoice. As soon as I receive payment, I’ll transfer this along.
This is also the site with the IE8 menu problem. So, if they truly want it fixed, I’ll tell them we need to hire a professional and I’ll be back in touch regarding that.
Thank you, my friend!
EDIT: And I know nothing about your mobile app… but I would imagine they would be interested since probably ALL of their users will have mobile devices.
Is there a link I can send them explaining more about it? Will it work on a multi-site sub-directory installation.
Admin
No worries. Glad to see the theme is generating some income for you 🙂
Thanks. What about my EDIT above?
Viewing 10 posts - 1 through 10 (of 12 total)
- 1
- 2
- You must be logged in to reply to this topic.
