Enter your search term

Search by title or post keyword

How to Set up WordPress User Redirect After Login

Our website is supported by our users. We sometimes earn affiliate links when you click through the affiliate links on our website

Contact us for Questions

Where your user lands after logging into your WordPress website has a significant impact on user experience.

By default, when users log in to a WordPress website, depending on their roles, they are either redirected to the admin area or profile section on the WordPress backend.

To avoid any interaction with the backend of your site, you may want to redirect users to any other part of your website.

For instance, a blogger may want to redirect subscribers to the blog page, a membership site may want his log-in user on their forum page and an online store may want users to land on the store page, shopping cart, or wishlist.

This tutorial will walk you through how to implement WordPress redirect after login using 2 different methods.

What is the Best Way to Automatically Redirect in WordPress?

The best way to automatically redirect in WordPress is to use a redirection plugin. It’s safe and easy.

While It’s possible by writing some PHP command and inserting it in your theme folder, It’s not advisable for beginners as any mistake here could cause hard-to-fix damage to your site. Using a WordPress plugin poses no threat whatsoever.

What You’ll Need to Set up WordPress User Redirect After Login

  • WordPress Admin Access:  Out of the 6 roles in WordPress, only a user with an admin or super admin role can make certain modifications on a WordPress website. You need either access to set up user login redirects.
  • WordPress Redirection Plugin: Plugins are the fastest and simplest route to getting things done in WordPress, URL redirects inclusive. We’ll show you some of the best plugins for redirection and how to use the coming section.
  • Web Host Cpanel: To use code for redirecting a page in WordPress, you need access to your  WordPress core files as you’ll be adding the code to your theme file. The easiest route to this file is to log in to your WordPress hosting account Cpanel and open your site file manager
  • Basic PHP Programming Knowledge: If you chose the coding option for setting up user redirect after login, you need to be familiar with the coding language of WordPress which is PHP.

How to Set up WordPress User Redirect After Login: 2 Methods

When it comes to redirecting users in WordPress, you have two options, code it yourself or use a plugin.

If you are an advanced WordPress user with some PHP Programming know-how, coding redirects yourself is simply the best option.

You won’t be adding an extra plugin to your site and you’ll save yourself the headache of updates, bugs, and vulnerabilities that might come with it.

That said, the majority of WordPress users have zero coding knowledge. But thanks to plugins, any feat achievable with codes is possible with plugins.

Moreso, mistakes in a single line of code can mess up your website. So if you aren’t comfortable with codes, use a plugin.

That said, now let’s look at both options step by step.

  • Method #1: Using Plugins to Set up WordPress User Redirect After Login
  • Method #2: Manually Set up WordPress Login Redirect with Custom Code

Method #1: Using Plugins to Set up WordPress User Redirect After Login

There are several plugins you can opt for this purpose. While some are specifically designed for login redirects, others have it as part of their main function.

An Example is WPForms which has login redirects as part of its User Registration Addon.

Unless your login forms are already created with such plugins, using a dedicated redirect plugin is better. We’ll use LoginWP for this tutorial.

Using LoginWP Plugin to Set up WordPress User Redirect After Login

From experience, the simplest way to redirect WordPress users after login is to use the LoginWP (formerly Peter’s Login Redirect) plugin.

Untitled 51

The plugin lets you redirect logged-in users depending on their roles, username, capability, etc.

With a few clicks, you can quickly configure login redirects for various user scenarios.

Let’s see.

First thing first, you need to install and activate the plugin.

Check out this comprehensive WordPress plugin installation guide if you need help.

After activating the plugin, a new tab named LoginWP will be added to the left panel of your admin dashboard.

Click on it and select Redirection from the options.

Untitled 11

You’ll be taken to the setup page. Once there, let’s take a look at some of the login redirection rules you can set on this page.

Untitled 32

Set up WordPress Login Redirection for Specific Users

With LoginWP, you can redirect a specific user to any other page on your website. This feature can come in handy if you have a small internal team and want your team member to interact with a particular page.

Here are the steps involved.

On the Redirection Rules section, click the Add New button at the top.

With that, you’ll be taken to another screen where you can set your redirection settings.

Navigate to the Rule Condition dropdown and choose Username.

In the field next to it, you’ll see a dropdown with the list of all registered users on your website. Locate the name of the user you want to be redirected from the list and click to select.

Untitled 16

Next, is the Redirect URL section. This is where you enter the URL of the page you want that user to be redirected to after logging in or logging out.

So, enter the Login and logout URLs in their respective fields  and click the Save Rule button at the top

Untitled 56

And that’s all. You’ve finished setting up WordPress login redirects for that specific user.

When next the user login to WordPress, they’ll land on the page whose URL you input in the Login field. You can repeat the steps for as many users as you want to redirect.

Set up WordPress Login Redirection for User Roles

You can also set up login redirects by using WordPress user roles. For instance, as a blog owner, you may want your writer to be redirected to the admin area upon login while other users go to the home page.

Here’s how.

Click the Add New button on the same Redirection Rule page.

Go to Rule Condition and select User Role.

Next, choose the role to redirect from the drop-down under it.

Untitled 60

Next, you’ll see the Order field.

What this does is that it dictates how the rule will be displayed in the plugin settings. You can use any number depending on how you want your rule to be ordered.

After that, scroll to the Redirect URLs section and enter the Login URL. Set the Logout URL as well if you like.

Click the Save Rule button to apply your settings.

That’s it. Henceforth, any user with the role you selected will be redirected to the new Login URL.

If you want to do this for other user roles, simply follow the same steps.

Set up WordPress login Redirect based on User Capabilities.

An interesting feature in LoginWP that you can hardly find in other plugins is the ability to configure login redirect rules by users’ capabilities.

This feature is very useful for WordPress websites where users are managed with custom capabilities.

The steps are the same as above. Let’s see.

Start by clicking the Add New button on the Redirection Rule page.

Under Rule Condition, select User Capability from the drop-down and choose the user capability you want to redirect from the list.

You’ll see different user capabilities here depending on the user’s roles on your website.

Untitled 65

Next, use the Order fields to state how the rule you just set is organized in the plugin settings page.

Finally, input the Login and Logout URL in the box next to each field and click the Save Rule button.

Set up WordPress Login Redirect for All Users

If you want all your WordPress users irrespective of their roles to land on a particular page, you can create a sitewide redirect for all users.

Likewise, for users who don’t fall under any of the Redirection Rules you’ve set above, then you can specify the page you want those user’s redirected to.

Just go back to the main redirection page and scroll to the All Other Users section.

Enter the Login and Logout URL in the available fields.

Untitled 69

Remember to click the Save Changes button to apply your rule.

Set up WordPress Redirect for Users After Registration

By default, when new users sign up on a WordPress website, they are automatically redirected to the login page.

If you want newly registered users to be taken to any other page on your website, there’s a straightforward way to do it with LoginWP.

Simply scroll to the After Registration section on the main redirection page, enter the desired URL, and click the Save Changes button.

Untitled 74

And that’s all. You’ve successfully learned how to set up WordPress login redirects for the different scenarios using the LoginWP plugin.

Other plugins that work in the same way include Sky Login Redirect, After Login Redirect, and WP Login and Logout Redirect.

Method 2: Manually Set up WordPress Login Redirect with Custom Code

If you don’t fancy the idea of an extra plugin to your WordPress websites or you’ve tried some plugins that didn’t work for you.

Using a custom code for WordPress login redirect is the next option. You don’t need to be a Programming guru to use custom code to set up WordPress login redirect.

If you understand the basics of PHP and are familiar with WordPress core files, you should be able to follow the steps in this guide.

Before modifying your WordPress core files, you should first create a backup of your website. Anything can happen when executing custom codes in WordPress.

You want to err on the side of caution. Should in case something goes wrong, you can easily restore your WordPress websites from the backup.

We’ll be writing our custom redirection code with the WordPress login redirect filters.

You should also understand how the login redirect filter works to apply them correctly. You can learn more about it on the WordPress official developer page.

For this example, we’ll use the most basic filter to show you how to redirect all your WordPress users to your website homepage upon logging in.

This is what the code looks like:

function custom_login_redirect() {

return ‘home_url()’;

}

add_filter(‘login_redirect’, ‘custom_login_redirect’);

What this code does is that the add_filter hook calls the custom login redirect function which contains the instruction to return the user to the homepage “home_URL()” when they log in.

If you want to redirect users to somewhere else on your website, all you need is to replace the home_URL() part with the destination you want users to be redirected to after login.

Now that you understand how the code works, the next thing is to add the code to WordPress.

There are two ways to do this: First, you can add the code directly to your theme file or use a code snippet plugin to insert the code.

Let’s see how to use both methods.

Adding WordPress Login Redirect Code to Theme File

If you choose to insert the login redirect code to your theme file, then It’s advisable to do it with your child theme. Else, you’ll need to reinsert the code every time you upgrade WordPress or update the theme.

There are several ways to edit theme files, WordPress built-in theme file Editor, Cpanel File Manager, or SFTP/FTP client software.

We’ll show you how to use the first 2 methods. So, if one doesn’t work for you, you can use the other.

Using Built-in Theme File Editor

Log in to your WordPress admin area, locate Appearance on the left panel, and select Theme File Editor from the options.

Untitled 77

On the Editor Screen, go to the Theme File sidebar and locate Theme Function (function.php) under it. Click to open the file.

Once it opens, scroll to the bottom and paste the login redirection code above.

Click the Update File button to save your changes.

Untitled 81

And that’s all. The WordPress login redirection code is now active on your site.

To confirm, log out and log in back. You should be redirected to your homepage.

Some themes won’t allow you to edit their files using this method. If that’s your case, you can edit WordPress files from your web host Cpanel File Manager.

Using Cpanel File Manager

Login to your hosting account dashboard, Locate File Manager and double-click to open.

Untitled 22

Note, your interface may look different depending on your hosting provider.

Don’t worry. You only need to locate the File Manager.

Once you are in, navigate to public_html > wp-content > themes > Your_theme_name.

Open the theme folder, you should see the function.php file inside it.

Right-click on it and select Edit from the options.

Untitled 27

Once the file opens, scroll to the bottom and insert your login redirect code.

Untitled 35

Finally, click the Save icon at the top right.

Adding WordPress Login Redirect Code with a Plugin

Of the two methods, the easiest way to add a login redirect code to WordPress is to use a code snippet plugin.

There are several plugins you can use to insert code in WordPress, we’ll use Code Snippets for this tutorial.

Let’s see.

After installing the Code Snippets plugin, go to the left panel of your admin dashboard and locate the Snippets tab.

Hover over it and select Add New from the options.

Untitled 41

On the Add New Snippet page, stay on the Function tab and paste your login redirect code in the available field.

Untitled 45

On the bottom bar, you have options to run the code snippet everywhere, only on the admin area, only in the site front end, or only run once. Since we want to activate sitewide redirects, we’ll select the Run snippet everywhere option.

Finally, Click the Save Changes button and Activate the snippet.

And that’s all.

You’ve successfully added the WordPress login redirect code with a plugin.

More Helpful WordPress Tutorials:

Wrapping up

WordPress login redirect enables you to take your user directly to where you want them, the homepage, blog, shopping cart, forum, etc, instead of the default admin area or profile section.

We’ve shown you two methods to easily set up WordPress login redirects, manually or with a plugin.

While the latter appears more beginner-friendly, you should be aware that each method has its pros and cons.

We hope this guide helps you set up WordPress login redirect on your site. If you have further questions, feel free to reach out in the comment section below.

Leave a Comment