WordPress: Redirect Users After Log In

First, the code…

// Redirect admins to the dashboard and other users elsewhere
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
function my_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 );
	}
}

Then, some explanation…

For more information on this filter, read up on the login redirect filter.

In short, this function sends administrators to the WordPress Dashboard after log in and everyone else to the homepage of the site. To send everyone else to a specific page on your site, replace the id ’83’ to the id of the page. Don’t forget to comment and uncomment the necessary lines.

11 thoughts on “WordPress: Redirect Users After Log In”

  1. Thanks Josh. I really don’t understand why the default installation of WordPress doesn’t redirect users to the dashboard. Sending them to the edit profile page makes no sense to me.

  2. Thanks Josh… this hit the spot and saved using a plugin.
    Needed to send subscriber members to a member-dashboard and not the wp-admin profile page as that would have confused them.
    Worked great 1st time!

  3. Thanks for the code, looks like exactly what we need. Does this get pasted into the functions.php or wp-login.php?

  4. Any idea how to do the same with WooCommerce. They automatically redirect users to the My account page upon login/registration. I’d like for the user to be redirected to the homepage.

    I’ve tried your code, but it works for the standard WP login, but not WooCommerce. Perhaps I’m putting it in the wrong file?

  5. Where do I put this code? I can’t figure out where to put it, or where to call it? I don’t know how to make plugins if that is what they want me to do. Please help.

  6. I was looking for this article almost the entire Internet! I knew I’ve seen someplace (here) but just did forget to save it.
    I needed as I’m looking to allow members to see some content on a website but not getting into a Dashboard of themselves as they don’t need that.

  7. I searched everywhere for a solution too. This finally did the trick. I had no problem redirecting users after logging in, my problem was with the URL sent in the new user email. If a user logged in using that link it would still redirect to the profile page in the admin.

    I didn’t want to use a plugin to fix it and none of the functions for editing the new user email worked, but this worked without having to edit the new user email.

    I also installed the Profile Builder plugin strictly for them to be able to change their password from the front end.

    Thanks for this.

Leave a Reply

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