Last active
December 2, 2021 22:04
-
-
Save eleanorcode/f1bdd6fc2143c9fe9d1d329c5919b7fb to your computer and use it in GitHub Desktop.
Redirect Users after Login in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function custom_login_redirect( $redirect_to, $request, $user ) { | |
| if ( isset( $user->roles ) && is_array( $user->roles ) ) { | |
| if ( in_array( 'administrator', $user->roles ) || in_array( 'editor', $user->roles ) || in_array( 'author', $user->roles ) ) { | |
| $redirect_to = admin_url(); | |
| } else if ( in_array( 'customer', $user->roles ) || in_array( 'shop_manager', $user->roles ) ) { | |
| $redirect_to = home_url( '/shop' ); | |
| } else { | |
| $redirect_to = home_url(); | |
| } | |
| } | |
| return $redirect_to; | |
| } | |
| add_filter( 'login_redirect', 'custom_login_redirect', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment