Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save taricco/1b10135feec7bd1c6c230670611bc1eb to your computer and use it in GitHub Desktop.

Select an option

Save taricco/1b10135feec7bd1c6c230670611bc1eb to your computer and use it in GitHub Desktop.
/*** 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