# Send Users to Their Own Site After Login

> When someone logs in on a site where they are not a member, sends them to the dashboard of their primary site instead of an error page.

- Type: PHP
- Runs: Run everywhere
- Category: [Multisite](https://wpide.com/library/category/multisite/)
- Tags: login, redirect, users
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/ms-login-redirect-primary-site/

## Code

```php
if ( ! is_multisite() ) {
    return;
}

add_filter( 'login_redirect', function ( $redirect_to, $requested, $user ) {
    if ( ! $user instanceof WP_User || is_super_admin( $user->ID ) || is_user_member_of_blog( $user->ID ) ) {
        return $redirect_to;
    }

    $primary = get_active_blog_for_user( $user->ID );

    return $primary ? get_admin_url( $primary->blog_id ) : $redirect_to;
}, 10, 3 );
```

## Notes

Users who belong to the site they log in on are redirected as usual.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Send Users to Their Own Site After Login" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
