JiveDig
11/1/2013 - 3:24 PM

Redirect user after login - admins to dashboard and other users elsewhere

Redirect user after login - admins to dashboard and other users elsewhere

// Redirect admins to the dashboard and other users elsewhere
// @link http://www.remicorson.com/tip-redirect-a-wordpress-user-after-login/
add_filter( 'login_redirect', 'xxx_login_redirect', 10, 3 );
 
function xxx_login_redirect( $redirect_to, $request, $user ) {
    // Is there a user?
    if ( is_array( $user->roles ) ) {
        // Is it an administrator?
        if ( in_array( 'administrator', $user->roles ) )
            return home_url( '/wp-admin/' );
        else
            return home_url();
            // return get_permalink( 83 );
    }
}