Created
August 3, 2024 14:16
-
-
Save taricco/1b10135feec7bd1c6c230670611bc1eb to your computer and use it in GitHub Desktop.
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
| /*** Redirect logged in users from Login page to Dashboard automatically ***/ | |
| add_action('template_redirect', 'redirect_logged_in_users'); | |
| function redirect_logged_in_users() { | |
| // Check if the user is logged in | |
| if (is_user_logged_in()) { | |
| // Get the current URL | |
| $current_url = home_url($_SERVER['REQUEST_URI']); | |
| // Define the URL to check | |
| $target_url = home_url('/members/'); | |
| // Define the redirection URL | |
| $redirect_url = home_url('/members/dashboard/'); | |
| // Check if the current URL matches the target URL | |
| if ($current_url === $target_url) { | |
| // Redirect to the dashboard URL | |
| wp_redirect($redirect_url); | |
| exit(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment