roles ) ) || ( in_array( "editor", $user->roles ) ) ) { return $redirect_to; } else { return home_url(); } } else { return $redirect_to; } } add_filter("login_redirect", "admin_login_redirect", 10, 3);" /> roles ) ) || ( in_array( "editor", $user->roles ) ) ) { return $redirect_to; } else { return home_url(); } } else { return $redirect_to; } } add_filter("login_redirect", "admin_login_redirect", 10, 3);" />

WordPress Login Redirect For Different User Roles

Home/WordPress Login Redirect For Different User Roles

From time to time clients come to me requesting login redirects in WordPress. The following handy snippet below allows you to specify where the user lands once they’ve logged in, based on user roles. In the example, users with Administrator and Editor roles are redirected to the Dashboard, whilst everyone else gets redirected to the site’s homepage.

Add the code to your theme’s functions.php file.

function admin_login_redirect( $redirect_to, $request, $user )
{
    global $user;
    if( isset( $user->roles ) && is_array( $user->roles ) ) {
        if (( in_array( "administrator", $user->roles ) ) ||  ( in_array( "editor", $user->roles ) ) ) {
            return $redirect_to;
        } else {
            return home_url();
        }
    }
    else 
    {
        return $redirect_to;
    }
}
add_filter("login_redirect", "admin_login_redirect", 10, 3);
2017-05-19T15:48:04+00:00 August 29th, 2015|WordPress Snippets|0 Comments

About the Author:

Warren Chandler is a freelance web programmer and web developer, based in Frinton on Sea, Essex. Warren specialises in web programming, web design, corporate identity, copy writing, SEO, logo and print media for home, work, and mobile platforms.

Leave A Comment