How to Redirect Non-Admin Users to a Custom Page After Login
How to Redirect Non-Admin Users to a Custom Page After Login
When users log into a WordPress site, they are typically redirected to the dashboard. However, for non-admin users, it might be better to send them to a custom page, such as a members-only area, a welcome page, or a user-specific dashboard.
In this guide, we’ll show you how to automatically redirect non-admin users to a specific page after login using a simple code snippet.
Why Redirect Non-Admin Users?
Redirecting non-admin users can help:
- Improve user experience by directing them to relevant content.
- Prevent users from accessing the WordPress admin area.
- Enhance security by limiting dashboard access.
Code Snippet: Redirect Non-Admins After Login
To redirect non-admin users to a custom page, add the following code to your theme’s functions.php
file or use the Code Snippets plugin:
Explanation
login_redirect
Hook: Filters the URL users are redirected to after logging in.$user->roles
: Checks the user’s role.home_url('/custom-page/')
: Redirects non-admin users to the specified page.
Redirect Users Based on Role
If you want to redirect different user roles to different pages, use this modified snippet:
Explanation
- Subscribers go to
/subscriber-dashboard/
. - Editors go to
/editor-dashboard/
. - Admins are redirected normally.
Using a Plugin for Redirection
If you prefer not to use code, you can install a plugin like:
- Peter’s Login Redirect
- LoginWP (formerly Peter’s Login Redirect)
These plugins allow you to set up user-specific or role-based redirections without modifying code.
Conclusion
Redirecting non-admin users to a custom page after login improves user experience, enhances security, and ensures they land where they need to be. Whether using a simple function or a plugin, implementing this feature can optimize your WordPress site’s navigation.