Close Menu
wpexpelorwpexpelor
  • WordPress Beginner tips
  • WordPress Security
  • Services
  • about us
  • contact us
Facebook X (Twitter) Instagram Pinterest
Facebook X (Twitter) Instagram Pinterest
wpexpelorwpexpelor
  • WordPress Beginner tips
  • WordPress Security
  • Services
  • about us
  • contact us
wpexpelorwpexpelor
Home»WordPress Beginner tips»How to redirect user after login WordPress?
WordPress Beginner tips

How to redirect user after login WordPress?

NinaBy NinaNovember 7, 2023Updated:December 3, 20231 Comment3 Mins Read
redirect user after login wordPress
redirect user after login wordPress
Share
Facebook Twitter LinkedIn Pinterest Email
5/5 - (1 vote)

 How to redirect user after login wordPress? Sometimes, you need to redirect user after login in WordPress. But how and why should you even need to do so?! Here is an example: suppose you need to redirect any users with customer role to your shop home page, and this definitely leads to a better user experience. 

In another case, you may need to redirect user that has login in WordPress to an online assessment form. 

Any way! You need to redirect user, and here we are to show you how to redirect user after login in WordPress. You can learn how to redirect user by role, username, or whatever you want by reading this article. As usual, there are two ways. You can redirect users after logging in WordPress with a plugin or without a plugin. We cover Both procedures in this article of wpexpelor.

Contents show
1 Redirect user after login WordPress with plugin
2 Redirect user after login WordPress without plugin

 Redirect user after login WordPress with plugin

To redirect user after login in WordPress with plugin, fallow the steps:

  1. Click on the plugin parts to access the WordPress repository.
  2. Search “LoginWP” and install and activate the plugin.
  3. As we have shown in the picture, from the dashboard, go to the “Redirections” part.
  4. From “Redirection Rules” part, click the add button.
  5. From “Rule Condition” part, you can define different rules based on username, role, etc., and you can even define new rules.
wpexpelor loginWP plugin
wpexpelor loginWP plugin

How do the rules work here? Suppose we have defined a rule for administrative roles in our system. The “Order” field shows the importance of the situation. Number 1 has the most importance, and as the number decreases, the priority increases. 

wpexpelor loginWP plugin add roles
wpexpelor loginWP plugin add roles

From “Redirect URLs”you can set which user roles would be redirected to which pages. This trick can be implemented even after user log out of your site. (redirect user after logout in WordPress).

For example, we have defined admin user should be redirected to the shop home page after login, and he should be redirected to the “cart” after logging out!

wpexpelor loginWP plugin setting
wpexpelor loginWP plugin setting

Eventually, save the role that you have defined. 

Redirect user after login WordPress without plugin

There are so many reasons that people don’t want to use WordPress plugins to get the job done! You may have another plugin that interferes with this one. So in wpexpelor we try to provide you with both ways. 

Redirect user after login WordPress without plugin
Redirect user after login WordPress without plugin

To Redirect user after login in WordPress without plugin copy and paste this code in to the functions.php file in your WordPress theme.

Note! For consistent changing, use child theme. 

This code will implement your rule for all user roles. In fact, all user will be redirected to the same page after login in WordPress.

function custom_redirect_after_login() {
    if (is_user_logged_in()) {
        wp_redirect('https://example.com/your-desired-page/');
        exit;
    }
}
add_action('template_redirect', 'custom_redirect_after_login');

If you want to refactor the code based on user role, here is the result:

function custom_redirect_based_on_role() {
    if (is_user_logged_in()) {
        $user = wp_get_current_user();
        
        if (in_array('subscriber', $user->roles)) {
            wp_redirect('https://example.com/subscriber-page/');
        } elseif (in_array('customer', $user->roles)) {
            wp_redirect('https://example.com/customer-page/');
        } elseif (in_array('administrator', $user->roles)) {
            wp_redirect('https://example.com/admin-page/');
        } else {
            wp_redirect('https://example.com/default-page/');
        }

        exit;
    }
}
add_action('template_redirect', 'custom_redirect_based_on_role');

As you see in this code, we have separated the roles and target page.

Note: replace your desired page URL with our test addresses! 

feel free to ask any questions in comments.Hope the article is useful for you.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit VKontakte Telegram WhatsApp
Previous ArticleHow to disable WordPress plugin update notification?
Next Article WordPress gallery shortcode: all you need to know + picture

Related Posts

woocommerce user registration form without email

June 9, 2024

Edit Author Slug in WordPress

January 30, 2024

install 2 wordpress on same domain

January 23, 2024

1 Comment

  1. John on November 17, 2023 6:18 pm

    Thank you for sharing your knowledge on how to redirect users after login in WordPress. I always struggle with figuring out the best way to do this, and your blog post has given me some great ideas. I especially appreciate your step-by-step instructions and the mention of using a plugin – that will definitely save me time and effort in the future. Keep up the great work!

    Reply

Leave A Reply Cancel Reply

Trending
WordPress Beginner tips

woocommerce user registration form without email

By NinaJune 9, 20240

Woocommerce user registration form without email? Is it possible? Customers demand easy ways to buy…

WordPress Reset Password Via Database

December 14, 2023

Running honeypot in the WordPress

September 7, 2023

E-Commerce Seo Services in Austin

July 7, 2025

pingbacks and trackbacks

July 4, 2025
Social
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
Facebook X (Twitter) Instagram Pinterest
©2025 WPexpelor. All Rights Reserved.

Type above and press Enter to search. Press Esc to cancel.