How to share primary navigation of main site with subsites usining switch_to_blog

I worked it out.

I didn’t enter the correct hook. Here is the code that works for a genesis framework site.

add_action('genesis_after_header', 'primary_library_menu_switch');
    function primary_library_menu_switch() {
        global $blog_id;
        if ( ! is_multisite() || 2 == $blog_id ) {
        switch_to_blog( 1 );

        wp_nav_menu( array(
            'menu'              => 2,
            'fallback_cb'       => false,
            'menu_class'        => 'genesis-nav-menu',
            'theme_location'    => 'primary'
        ) );

        restore_current_blog(); 
    }
    }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)