Filters the login redirect URL.
Parameters
Source
$redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user );
Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |
Filters the login redirect URL.
$redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user );
Version | Description |
---|---|
3.0.0 | Introduced. |
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.
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.
Example Migrated from Codex:
Redirect all logins to the homepage with an anonymous function (php 5.3+).
Thanks WP Scholar : https://wpscholar.com/blog/wordpress-user-login-redirect/ :D
$user->has_cap()
to check a role is discouraged as it may produce unreliable results.