Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using this function to switch to my main website's navigation and display it on all sub sites in my multisite network. Ideally the links should have the following format:

http://www.mysite.com/navigation-link

but on the sub-sites the urls are http://www.mysite.com/subsite/navigation-link

Obviously these pages don't exist so it's just showing a blank page. Any idea how I could make sure the urls are like the first example and how I might incorporate that into my function?

function wp_multisite_nav_menu() {

    global $blog_id;

    $args = array(
            'menu' => 'Main Menu',
            'theme_location' => 'main-nav'

        );

    $main_blog = 1; 

    $main_blog = absint( $main_blog );


    if ( !is_multisite() || $blog_id == $main_blog ) {
        echo wp_nav_menu( $args );
        return;
    }

    else {

    switch_to_blog( 1 );

    echo wp_nav_menu( $args );

    restore_current_blog();

    }

}
share|improve this question

1 Answer 1

You just need the last part of your function where you switch to blog 1 and get the menu.

function wp_multisite_nav_menu() {

$args = array(
        'menu' => 'Main Menu',
        'theme_location' => 'main-nav'

    );

switch_to_blog( 1 );

echo wp_nav_menu( $args );

restore_current_blog();

}

share|improve this answer
    
Thanks, but that still doesn't fix the URL issue. –  chap Apr 11 at 8:30
    
It should. Maybe try to test on a local version with no plugins and a default theme first. The menu also needs to exist on the main site and put the code in your functions file. –  Innate Apr 11 at 12:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.