How to Redirect WordPress Users After Login – Complete Guide

Do you want to redirect WordPress users after login to your website to a specific page or URL?

Whether you’re managing a blog, an online store, or a membership site, it’s important to ensure that users are redirected to the correct page after logging in. This can significantly improve their experience and engagement with your WordPress website. This is particularly useful if you have different user roles (e.g., subscribers, contributors, administrators) and want to redirect each group to a different page based on their role.

Why Redirect WordPress Users After Login?

After logging in to WordPress, all users are directed to the admin dashboard by default. Although they will only be able to view and interact with the parts of the dashboard that they have permission to access, this behavior may not always be desirable.

Depending on the type of site that you operate, it may be more appropriate to direct new logins to a different location. You may even want to redirect users of different roles to completely different pages. For example, admins could be directed to the dashboard, while regular users could be taken to a welcome page.

In this article, we’ll learn how to redirect WordPress users after login using the WordPress login redirect feature in ProfilePress.

WordPress User Redirection Setting in ProfilePress

In ProfilePress, You can set the page or a custom URL to redirect users to after they log in, log out, and reset their password under the Redirection section of ProfilePress settings. See the screenshot below.

The URL entered in the custom URL field takes precedence over the selected page.

But what if you want to conditionally redirect users after they log in based on their WordPress user role and the membership plan they are subscribed to? See the next section.

WordPress Login Redirect Based on Membership Level

ProfilePress includes a powerful WordPress login redirect feature that lets you set up rules that specify where to redirect users after they login based on the membership plan or membership level they are subscribed to.

To set up login redirect, ensure you have the ProfilePress plugin installed on your website. If you don’t have one, purchase a license now.

Go to ProfilePress  >> Settings >> Login Redirect and scroll to the “Login Redirect Based on Membership Plan” section.

At the bottom right corner, select a membership plan for which you want to set up a login redirect and click the “Add Rule” button.

Finally, enter the URL path or slug to redirect to.

WordPress login redirect based on membership plan

In the screenshot above, WordPress users subscribed to the Gold plan will be redirected after login to https://wordpress.test/golden-welcome/, while those subscribed to the Silver plan to https://wordpress.test/silver-welcome/.

Redirect WordPress Users After Login Based on User Role

ProfilePress WordPress login redirect feature also lets you set up rules that specify where to redirect users after they log in based on their user role.

Go to ProfilePress  >> Settings >> Login Redirect and scroll to the “Login Redirect Based on User Role” section.

At the bottom right corner, select a user role you want to set up a login redirect for and click the “Add Rule” button.

Finally, enter the URL path or slug to redirect to.

WordPress login redirect by user role

In the screenshot above, we set up WordPress login redirects for the Subscriber and Administrator user roles, where the former is redirected after login to a welcome page (https://wordpress.test/welcome) and the latter to the WordPress admin backend (https://wordpress.test/wp-admin/)

Via Code Snippet

The code below only works if they log in via a ProfilePress-powered login form. And it should be pasted to your theme’s functions.php file or your site-specific / dummy plugin.

add_action( 'ppress_before_login_redirect', 'pp_redirect_by_role', 10, 3 );

function pp_redirect_by_role( $username, $password, $login_form_id ) {

	$a = get_user_by( 'login', $username );
	//retrieve the user roles
	$user_roles = $a->roles;

	/**
	 * we'll redirect users with a student role to https://xyz.com/student/
	 * and those with a teacher role to https://xyz.com/teacher/
	 */
	if ( in_array( 'student', $user_roles ) ) {
		$redirect = 'https://xyz.com/student/';
	}
	elseif ( in_array( 'teacher', $user_roles ) ) {
		$redirect = 'https://xyz.com/teacher/';
	}
	else {
		// default to login redirect url set in plugin settings
		$redirect = pp_login_redirect();
	}

	wp_redirect( $redirect );
	exit;
}

The code above checks the role of the user logging in. If the user is a student (i.e., has a “student” role), they get redirected to https://xyz.com/student/ and if it is a teacher (with a “teacher” role), they are redirected to https://xyz.com/teacher/

To include more user role checks and login redirection, create an additional `elseif` conditional block for them and have it in the above code.

Set up WordPress redirect after login today

Although it may not seem significant, the page where users land after logging in can significantly impact your website user experience. It can guide them to the desired locations, prevent confusion, and save time.

We hope this article helped you learn how to redirect users after a successful login to WordPress.

For other ways to customize the WordPress login experience, you might also be interested in our guides to create a custom login page, change the WordPress login URL, or set up a passwordless login.

If you have any pre-sale questions, inquiries, or contributions, please get in touch.

Create Paid Membership Websites in Minutes

Install ProfilePress today and get a modern and powerful WordPress membership & ecommerce website – the easy way!