Reply To: Log in redirect based on user role?

Home Forums User Registration Log in redirect based on user role? Reply To: Log in redirect based on user role?

#7170

sanjeev3
Member

Hello LFFprop,

Currently, we don’t have such feature. If you could add some codes, here it is:

add_filter( 'user_registration_login_redirect', 'ur_login_redirect', 10, 2 );
function ur_login_redirect( $redirect, $user ) {

	$user_meta  = get_userdata( $user_id );
	$user_roles = $user_meta->roles;

	if ( in_array( 'subscriber', $user_roles ) ) {
		$redirect = 'sample-page';
	} elseif( in_array( 'administrator', $user_roles ) ) {
		$redirect = 'my-account';
	}

	return $redirect;
}

Add the codes to your child theme’s functions.php. If you are unfamiliar with such stuffs, donot add anything, any error might result your site to crash. This is more of a developers guide.

Regards,
WPEverest Support