apply_filters( 'login_redirect', string $redirect_to , string $requested_redirect_to , WP_User|WP_Error $user )
Filters the login redirect URL.
Parameters Parameters
Source Source
File: wp-login.php
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Examples
This example redirects admins to the dashboard and other users to the homepage. Make sure you use add_filter outside of is_admin(), since that function is not available when the filter is called.
Expand full source codeCollapse full source code
Notes
You can register the login_redirect filter to use all 3 parameters like this:
In the example, ‘filter_function_name’ is the function WordPress should call during the login process. Note that filter_function_name should be unique function name. It cannot match any other function name already declared.
The $current_user global may not be available at the time this filter is run. So you should use the $user global or the $user parameter passed to this filter.
Expand full source codeCollapse full source code
Thanks WP Scholar : https://wpscholar.com/blog/wordpress-user-login-redirect/ :D
Feedback
$user->has_cap()
to check a role is discouraged as it may produce unreliable results. — By Chad Butler —