Support » Networking WordPress » Redirect logged in users to their primary dashboard

  • Feriman


    I have a WordPress multisite installation. When the user (who is not a super admin) logs in and then opens the dashboard of the main page (, he gets the message below:

    You attempted to access the “” dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the “” dashboard, please contact your network administrator.

    If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.

    Your Sites mysubsite Visit Dashboard | View Site

    I would like to automatically redirect these users to Visit Dashboard link instead of displaying the above message.

    I found these below PHP codes:

    This redirects the user to the primary dashboard when they try to log in to the dashboard of another subsite.

    add_filter('login_redirect', function($redirect_to, $request_redirect_to, $user)
        global $blog_id;
        if (!is_wp_error($user) && $user->ID != 0)
            $user_info = get_userdata($user->ID);
            if ($user_info->primary_blog)
                $primary_url = get_blogaddress_by_id($user_info->primary_blog) . 'wp-admin/';
                $user_blogs = get_blogs_of_user($user->ID);
                //Loop and see if user has access
                $allowed = false;
                foreach($user_blogs as $user_blog)
                    if($user_blog->userblog_id == $blog_id)
                        $allowed = true;
                //Let users login to others blog IF we can get their primary blog URL and they are not allowed on this blog
                if ($primary_url && !$allowed)
        return $redirect_to;
    }, 100, 3);

    And this one redirects all logged in users:

    function check_if_user_needs_redirecting(){
        $active_blog = get_active_blog_for_user(get_current_user_id());
        $blogid = get_current_blog_id();
        if ($blogid != $active_blog->blog_id){
            header('Location: '.$active_blog->siteurl.'/wp-admin/');
    add_action( 'init', 'check_if_user_needs_redirecting' );
    • This topic was modified 4 months ago by Feriman.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.