Skip to content →

Redirect a specific user role to a different location after login in WordPress

A small yet very handy code snippet to redirect user to a different location by user role after a successful login in WordPress .

 

function zt_login_redirect( $redirect_to, $request, $user ) {
	// check if there is any user
	if ( is_array( $user->roles ) ) {
	    // look for the specific user role we want to redirect i.e subscriber
	    if ( in_array( 'subscriber', $user->roles ) ){
	        return home_url( '/your/redirect/location/' );
	    }
	}
}

add_filter( 'login_redirect', 'zt_login_redirect', 10, 3 );

 

Published in WordPress Snippet

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *