How to redirect Users to a Custom Page After WordPress Login

Redirecting users to a custom page after WordPress login can be achieved using a plugin (easiest) or custom PHP code (more control). This is most often done to provide a tailored experience based on the user’s role.

🛠️ Method 1: Using a Plugin (Recommended)

Plugins simplify the process, especially if you need different redirects for different user roles (e.g., Subscribers to a member dashboard, Editors to the Posts list).

  1. Install a Redirection Plugin:
    • Go to Plugins 🠆 Add New in your WordPress dashboard.
    • Search for a plugin like LoginWP (formerly Peter’s Login Redirect) or ProfilePress.
    • Install and Activate the plugin.
  2. Configure Redirection Rules:
    • Navigate to the plugin’s settings page (often found under Settings, Tools, or its own menu item like LoginWP).
    • Look for the option to add a new redirect rule.
    • Set the Condition: Choose the criteria for the redirect:
      • User Role: (e.g., Subscriber, Editor, Author)
      • Individual User: (e.g., a specific username)
      • All Other Users (as a general fallback rule)
    • Set the Destination: Enter the URL or select the Page where the user should be redirected after a successful login. This could be a static page like /welcome/ or a dynamic area like the Author’s post-editing screen.
    • Save the Rule: Ensure you save your changes to activate the redirect.

💻 Method 2: Using Custom Code

This method involves adding a function to your theme’s functions.php file (or a custom plugin) using the WordPress login_redirect filter. Always use a Child Theme when adding custom code.

  1. Access the functions.php File:
    • Go to Appearance 🠆 Theme File Editor in your dashboard and select your Child Theme (if you have one). If you don’t have a child theme, install one or use a code snippet plugin to avoid losing changes upon theme updates.
  2. Insert the Code:
    • Add the following PHP snippet. This example demonstrates redirecting an Administrator to the default dashboard and a Subscriber to a custom front-end page.
/**
 * Redirects users to a specific URL after login based on their role.
 */
function custom_login_redirect_by_role( $redirect_to, $request, $user ) {
    // Check if the user object is valid
    if ( isset( $user->roles ) && is_array( $user->roles ) ) {

        // Get the user's highest role (first in the array)
        $role = $user->roles[0];

        switch ( $role ) {
            case 'administrator':
                // Administrators go to the standard admin area
                return admin_url();
            case 'subscriber':
                // Subscribers go to a custom front-end page
                return home_url( '/member-dashboard/' );
            default:
                // Fallback for all other roles
                return home_url();
        }
    }
    // If the user object is not valid, return the original redirect URL
    return $redirect_to;
}
add_filter( 'login_redirect', 'custom_login_redirect_by_role', 10, 3 );
  1. Customize the URLs:
    • Replace home_url( '/member-dashboard/' ) with the path to your desired custom page.
    • You can modify the case statements to target any user role (e.g., 'editor', 'author') and set their specific destination.
  2. Save the File: Save the changes and test the login with different user accounts.

📚 Reference List

  • LoginWP (Formerly Peter’s Login Redirect): A widely used plugin for setting up user, role, and capability-based login redirects in WordPress.
  • WordPress Code Reference: login_redirect Hook: Official documentation on the filter hook used to customize the redirect URL after a user logs in.
  • Kinsta. (2025). How To Redirect WordPress Users After Login: Article providing detailed instructions for both plugin and code-based methods for managing post-login redirects.

Our Score
Click to rate this post!
[Total: 0 Average: 0]
Visited 1 times, 1 visit(s) today

Leave a Comment

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