Read Multisite Navigation from Main site

Recently switched to X-Theme and I am trying to iron out some bugs. I was using a workaround by switching to Blog 1 for the Navigation and switch Back afterwards… where would I place this code in XTheme, using Ethos?

Thanks

Hello There,

Thanks for writing in! Because what you are trying to accomplish requires a template customization, we would highly to suggest that you use a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

After the child theme is set up, please add the following code in your child theme’s functions.php file

// Output Primary Navigation
// =============================================================================

if ( ! function_exists( 'x_output_primary_navigation' ) ) :
  function x_output_primary_navigation() {

    if ( x_is_one_page_navigation() ) {

      wp_nav_menu( array(
        'menu'           => x_get_one_page_navigation_menu(),
        'theme_location' => 'primary',
        'container'      => false,
        'menu_class'     => 'x-nav x-nav-scrollspy',
        'link_before'    => '<span>',
        'link_after'     => '</span>'
      ) );

    } elseif ( has_nav_menu( 'primary' ) ) {

      wp_nav_menu( array(
        'theme_location' => 'primary',
        'container'      => false,
        'menu_class'     => 'x-nav',
        'link_before'    => '<span>',
        'link_after'     => '</span>'
      ) );

    } else {

      echo '<ul class="x-nav"><li><a href="' . home_url( '/' ) . 'wp-admin/nav-menus.php">Assign a Menu</a></li></ul>';

    }

  }
endif;

You will have to insert your switch_to_blog(1) and other customizations in the code above.

Hope this helps. Please let us know how it goes.

1 Like

Thank you, this works in the “x-child/functions.php” file

// Output Primary Navigation
// =============================================================================

if ( ! function_exists( 'x_output_primary_navigation' ) ) :
  function x_output_primary_navigation() {

	global $blog_id;
	$current_blog_id = $blog_id;
	if ( $current_blog_id != 1 ) { switch_to_blog(1); }

    if ( x_is_one_page_navigation() ) {
	
	wp_nav_menu( array(
		'menu'           => x_get_one_page_navigation_menu(),
		'theme_location' => 'primary',
		'container'      => false,
		'menu_class'     => 'x-nav x-nav-scrollspy',
		'link_before'    => '<span>',
		'link_after'     => '</span>'
	) );

	} elseif ( has_nav_menu( 'primary' ) ) {

	wp_nav_menu( array(
		'theme_location' => 'primary',
		'container'      => false,
		'menu_class'     => 'x-nav',
		'link_before'    => '<span>',
		'link_after'     => '</span>'
	) );

	} else {
	
	echo '<ul class="x-nav"><li><a href="' . home_url( '/' ) . 'wp-admin/nav-menus.php">Assign a Menu</a></li></ul>';

	}
	
	if ( $current_blog_id != 1 ) { switch_to_blog($current_blog_id); }
}
endif;

Hi,

Thanks for sharing your code.

Have a great day!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.