Redirect Users After Login

By default, WordPress redirects users to the dashboard after login, regardless of their role. On client sites or membership platforms, this can be confusing for non-admin users. This snippet allows you to redirect users based on their role—administrators go to the WordPress dashboard, while other users are redirected to a custom page (e.g., /dashboard). This improves user experience and workflow.

/**
 * WP Snippet Press - Redirect After Login
 */
function wpsnippetpress_redirect_user( $redirect_to, $request, $user ) {
    if ( isset( $user->roles ) && is_array( $user->roles ) ) {
        if ( in_array( 'administrator', $user->roles ) ) {
            return admin_url();
        } else {
            return home_url('/dashboard');
        }
    }
    return $redirect_to;
}
add_filter( 'login_redirect', 'wpsnippetpress_redirect_user', 10, 3 );
PHP

Usage:

Redirects users to specific pages depending on role.

Benefits:

  • Role-Based Redirection – Tailors login experience depending on user role.

  • Improved User Experience – Non-admin users land on relevant pages immediately.

  • Safe & Lightweight – Uses a simple filter without additional plugins.

Frequently Asked Questions

Yes. Add additional if statements checking in_array(‘role’, $user->roles) for other roles.
No. Administrators are still redirected to the default WordPress dashboard.
Yes. You can add logic based on $user->ID or user meta to redirect individual users to specific pages.

Related Links

Related Snippets

Display Gravity Forms Entries for the Logged-In User
Display Gravity Forms submissions for logged-in users on the frontend using a simple shortcode. Learn...
Hide WooCommerce Prices for Non-Logged-In Users
Hide WooCommerce product prices for visitors who aren’t logged in. It will encourage users to...
Picture of Kishan D
Kishan D
I’m a web developer who builds with WordPress, WooCommerce, and Shopify, and I enjoy exploring React and creating gaming & tech content.

SHARE POST

Leave a Reply