7

So I'm basically upgrading an older site and I need to make it multisite as well for some blogs and such.

I'd like to have the main site Menu(created from the admin) available on the other sites in an elegant way. That is, every site has a theme and it would be nice if I could just wp_nav_menu() on every one.

Any ideas?

I took a look at switch_to_blog() but I see it's deprecated.

Cheers!

2

2 Answers 2

5

This is what I've used recently. It's very simple but it works well for me.

    function wp_multisite_nav_menu( $args = array(), $origin_id = 1 ) {

        global $blog_id;
        $origin_id = absint( $origin_id );

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

        switch_to_blog( $origin_id );
        wp_nav_menu( $args );   
        restore_current_blog();

    }

I've thrown this into a mu-plugin file that hosts a lot of small hooks and functions intended to run network wide.

2
  • solid answer - good one!
    – Q Studio
    Commented Apr 3, 2015 at 8:58
  • I've added this to an MU plugin, and things work on the main site (1) - but on sub sites in the network (2,3,4), they fallback to wp_page_menu due to not being found. Any ideas? The switch_to_blog() is working as I can retrieve data from the main site (get_bloginfo('name'), get_the_title(3) etc.), I just can't retreive menus. This doesn't seem to be working as it once was.
    – EHerman
    Commented Feb 3, 2016 at 23:52
2

I'd say: Write a short plugin that offers a simple function to output a menu. Then activate it network wide.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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