wordpress redirect after login

Trying to set up some redirect functionality for your WordPress login pages?

This functionality can come in really handy if you allow user registration on your site, especially for membership sites and ecommerce stores.

Fortunately, there are plenty of ways to create a redirect after WordPress login. For example, you can use a redirect after login plugin to handle the process for you. If you’re a more experienced user, you can also use a custom code snippet to do the job for you.

In this post, we’ll take a closer look at 🔎 why you might want to redirect users after they log into your site. Then, we’ll discuss three simple ways to make WordPress redirect after the login page. Let’s get started!

Why you might want (or need) to redirect your users

When users log into your site, they’re directed to the default admin area. While this can be fine for some types of websites, you might prefer to send users to specific web pages where they can perform certain actions.

For instance, if you run a membership site, you can send members to a page that contains a list of useful resources. You might also enable members to access their profiles instantly or view their account details.

If you run an ecommerce store, you likely have lots of users who log into your site before making a purchase. Therefore, it can be a good idea to redirect customers to a page where they can manage their payment and shipping details or view their wishlists.

Creating a custom redirect can be an effective way to personalize the user experience (UX) on your site. It can also help you make more sales and keep visitors engaged with your site for longer. While some membership and ecommerce plugins provide this functionality, there are other ways to enable the feature in WordPress.

Three ways to set up WordPress redirect after login

Now that you know why it’s useful to redirect your users, let’s take a look at three ways to set up redirects after login on your WordPress site…

  1. Use a WordPress redirect after login plugin
  2. Create a custom login form with redirect functionality
  3. Add a login redirect filter using Code Snippets

1. Use a redirect plugin for login pages

The easiest way to redirect users in WordPress is to use a dedicated plugin like LoginWP. With this tool, you can redirect specific users only, or redirect users according to their user roles and capabilities. The Pro version of the plugin also enables you to redirect users in different ways based on the page that they’re logging in from.

To get started, you’ll need to install and activate the plugin in your WordPress dashboard. Then, go to LoginWP > Redirection Rules:

How to make WordPress redirect after the login page with LoginWP

Here, click on Add New to create a new redirection rule. You can choose between three types of rule conditions:

Redirection rules

If you only want to redirect a specific user after the WordPress login, select Username. Then, find the correct user in the dropdown box to the right of the screen:

Redirect usernames

You can also use the Rule Condition dropdown menu to choose User Role. This way, you can set up the plugin so that all users with the same role are redirected to a specific web page. So, you could send editors to one URL and subscribers to another.

Finally, you can click on User Capability to redirect users based on their capabilities. For example, some users on your site may be able to delete posts and edit files, whereas others can only read your pages.

Next, you’ll want to insert the login and logout URLs where you want to redirect the user(s). Make sure to click on Save Rule to apply the changes.

To set up a set-wide redirection for all users on your site, go to LoginWP > Redirection Rules. Then, add the URLs in the All Other Users sections:

WordPress redirect after the login for all users

Finally, save your changes. That’s it – you’ve now created a WordPress redirect after the login page.

2. Create a custom login form with redirect functionality

You can also make WordPress redirect after the login page by creating a custom login form. One way to do this is to use a plugin like WPForms.

Note that the free version of the plugin has limited functionality and only lets you create contact forms. To use the login form feature, you’ll need the User Registration add-on, which is available on the Pro license ($199.50 for the first year and $399 at renewal).

For that reason, this method is best used if you’re already using WPForms for other premium functionality. If you only need the “after login” redirect functionality, you should consider a free alternative like Custom Login Page Styler.

Going forward, we’ll look at how the process works with WPForms, but the basic idea is the same with Custom Login Page Styler.

Once you’ve installed and activated the plugin in WordPress, head to WPForms > Settings to enter your license key. As mentioned, you’ll also need to install the User Registration Addon to build custom login forms.

When you have that out of the way, you can move forward with creating your form by going to WPForms > Add New:

Make WordPress redirect after login page using WPForms

Here, you can choose a template like the User Login Form or start with a blank form. Then, use the Add Fields section to edit, add, and remove fields:

WPForm fields

When you select a specific field like Email, you’ll land in the Field Options tab where you can change the label, add a description, and more:

WPForms field options

Once you’ve customized your login form, navigate to Settings > Confirmations:

Make WordPress redirect after the login page with Confirmations in WPForms

Under Confirmation Type, choose Go to URL (Redirect). Then, enter the URL where you want to redirect your users. Make sure to click on Save before exiting the form builder.

Now, you’ll need to embed your login form on a new or existing page on your website. All you have to do is add the WPForms block to your WordPress page:

Add login form to WordPress

Then, select the form you created earlier:

Add WPForms to your WordPress page

Now your login form (with the redirect) will automatically be added to your page.

3. Add a login redirect filter using Code Snippets

If you have experience with PHP, you can write your own code to make WordPress redirect after the login page. This way, you might be able to add further functionality to your site. However, you can still use a plugin like Code Snippets to help you insert the code easily.

To get started, you may want to use the WordPress login redirect filter to help you formulate your exact redirect code and understand how the function works.

Here’s an example of what it might look like:

function ti_custom_login_redirect( $url, $request, $user ) {
    if ( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
        if ( $user->has_cap( 'administrator' ) ) {
            $url = admin_url();
        } else {
            $url = home_url( '/cool-page/' );
        }
    }
    return $url;
}

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

This code works as follows:

  1. If an Administrator logs in, they’ll see the WordPress admin dashboard as usual.
  2. If any other user role logs in, they’ll be redirected to https://yoursite.com/cool-page/.

To make this code snippet your own, replace /cool-page/ with the actual URL slug that you want to redirect users to. For example, to set up a WordPress after login redirect to send users to https://yoursite.com/members/dashboard/, you would replace it with /members/dashboard/ (make sure to leave the single quotes on both sides).

You can use a plugin like Code Snippets to insert the code without editing your site files.

First, you’ll need to install and activate the plugin. Then, head to Snippets > Add New, switch to the Functions tab, and paste the code directly into the editor:

Add the WordPress redirect after login code to the Code Snippets plugin interface

You can leave the setting to Run snippet everywhere to redirect all WordPress users on your site. Then, click on Save Changes > Activate.

You can also get more creative and set up different WordPress redirects after login functionality based on a user’s role. You can find some code examples of this at the WordPress.org Developer Resources for this function.

Set up WordPress redirects after login today

If you run a membership site or ecommerce store, it can be useful (if not necessary) to redirect users after the WordPress login page. This way, you can send customers straight to their profiles or baskets.

Alternatively, you might enable members to manage their accounts immediately. Fortunately, there are different ways to set this up.

To recap, here are three ways to make WordPress redirect after the login page:

  1. Use a redirect plugin like LoginWP.
  2. Create a custom login form with a tool like WPForms (paid) or Custom Login Page Styler (free).
  3. Add a login redirect snippet.

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

Do you still have any questions about setting up a redirect after login? Let us know in the comments!

Yay! 🎉 You made it to the end of the article!

0 Comments
Inline Feedbacks
View all comments

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!