Use wp_nav_menu() to display a Menu from another site in a Network install?

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 s
2

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.

Leave a Comment