# Send Each Role to Its Own Page After Login

> Chooses where people land after logging in based on their role, for example editors to the posts list, customers to their account and subscribers to a members page.

- Type: PHP
- Runs: Run everywhere
- Category: [Redirects](https://wpide.com/library/category/redirects/)
- Tags: login, roles, redirect
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/login-destination-by-role/

## Code

```php
// Role => destination. {admin} means the wp-admin address.
$wpide_login_destinations = array(
    'administrator' => '{admin}',
    'editor'        => '{admin}edit.php',
    'author'        => '{admin}edit.php',
    'subscriber'    => '/',
);

add_filter( 'login_redirect', function ( $redirect_to, $requested, $user ) use ( $wpide_login_destinations ) {
    if ( ! $user instanceof WP_User ) {
        return $redirect_to;
    }

    if ( $requested && untrailingslashit( $requested ) !== untrailingslashit( admin_url() ) ) {
        return $redirect_to;
    }

    foreach ( (array) $user->roles as $role ) {
        if ( empty( $wpide_login_destinations[ $role ] ) ) {
            continue;
        }

        $target = $wpide_login_destinations[ $role ];

        return 0 === strpos( $target, '{admin}' ) ? admin_url( substr( $target, 7 ) ) : home_url( $target );
    }

    return $redirect_to;
}, 20, 3 );
```

## Notes

Use {admin} at the start of a value for an admin page, or a path on your site. Explicit redirect_to links, such as from a protected page, are respected.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Send Each Role to Its Own Page 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/
