Skip to content

Instantly share code, notes, and snippets.

@yuriinalivaiko
Created February 26, 2025 12:15
Show Gist options
  • Save yuriinalivaiko/0fb1252856b698342d4804b33173c689 to your computer and use it in GitHub Desktop.
Save yuriinalivaiko/0fb1252856b698342d4804b33173c689 to your computer and use it in GitHub Desktop.
Ultimate Member customization. Redirect logged in users from the Login page.
<?php
// Redirect logged in users from the Login page to the page specified in the role setting “Set Custom Redirect URL”.
add_action( 'template_redirect', function() {
if ( function_exists( 'um_is_core_page' ) && um_is_core_page( 'login' ) && is_user_logged_in() ) {
if ( um_user( 'login_redirect_url' ) ) {
$redirect_url = apply_filters( 'um_login_redirect_url', um_user( 'login_redirect_url' ), um_user( 'ID' ) );
} else {
$redirect_url = home_url();
}
exit( wp_safe_redirect( $redirect_url ) );
}
} );
@yuriinalivaiko
Copy link
Author

User Role settings:
UM User Roles, Edit Role (Login Options - welcome)

Alternative solution: you can use a page content restriction settings with the code snippet in the article How to Restrict & Redirect Login Page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment