Link from Main Site back to logged in user's Dashboard in Multisite

When a user logs into my multisite install, they are automatically redirected to the main site (elevatesites.com), where there's a training library.

On the menu of the main site, I want a link that says "DASHBOARD" that, when a user clicks on it, will send that user directly to the dashboard of THEIR blog (from the main site).

How can I achieve this?

Here's the front page of the main site and the dashboard link:
https://screencast.com/t/koVEJ9jV

For a more in depth example,

When user "johnc" logs in, he's taken to elevatesites.com (the training library)...

And when he clicks on the "DASHBOARD" link, he's automatically sent to *HIS* blog: http://johnexample.elevatesites.com

The same would go for ANY user. When they log in, each user will be sent to their own Dashboard.

  • Vaughan

    Hi Alex,

    Hope you're well?

    You would need to use some PHP code for this.

    You can try adding the following code to a mu-plugin.

    Create a file called custom_dashboard_menuitem.php

    <?php
    add_filter( 'wp_get_nav_menu_items', 'add_custom_nav_menu_items', 20, 2 );
    
    function add_custom_nav_menu_items( $items, $menu ){
        global $current_user;
    
        $user_id = get_current_user_id();
        $blogs = get_active_blog_for_user( $user_id );
    
        $dashboard_url = $blogs->siteurl . '/wp-admin'; // change wp-admin to any page/slug
    
        // only add item to a specific menu
        if ( $menu->slug == 'menu-1' ) { // Change menu-1 to the menu slug of the menuyou want to add this to.
          // only add profile link if user is logged in
          if ( get_current_user_id() ){
            $items[] = _custom_nav_menu_item( 'My Dashboard', $dashboard_url, 3 );
          }
        }
    
        return $items;
    }
    
    /**
     * Simple helper function for make menu item objects
     *
     * param $title      - menu item title
     * param $url        - menu item url
     * param $order      - where the item should appear in the menu
     * param int $parent - the item's parent item
     * @return \stdClass
     */
    function _custom_nav_menu_item( $title, $url, $order, $parent = 0 ){
        $item = new stdClass();
        $item->ID = 1000000 + $order + parent;
        $item->db_id = $item->ID;
        $item->title = $title;
        $item->url = $url;
        $item->menu_order = $order;
        $item->menu_item_parent = $parent;
        $item->type = '';
        $item->object = '';
        $item->object_id = '';
        $item->classes = array();
        $item->target = '';
        $item->attr_title = '';
        $item->description = '';
        $item->xfn = '';
        $item->status = '';
    
        return $item;
    }

    Change $menu->slug == 'menu-1' to the slug name of the Nav menu you are using in your theme.

    Now upload this file to /wp-content/mu-plugins/

    Hopefully, you should now see a Dashboard Menu Item on the front-end.

    Hope this helps

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.