Whenever I enter https://mydomain/wp-admin while not being logged in, I get redirected to
wp-login.php?redirect_to=https%3A%2F%2Fmydomain%2Fwp-admin%2F&reauth=1
With some help, I have created the following code to redirect users landing on the wp-login.php url to get forwarded to the desired custom page:
function redirect_wp_login_to_custom_login() {
global $pagenow;
$redirect_to;
$current_url = home_url ($_SERVER ['REQUEST_URI']);
if ('wp-login.php' == $pagenow) {
if (!is_user_logged_in ())
$redirect_to = get_home_url () . '/login/';
else {
if (is_super_admin() || is_admin())
$redirect_to = get_home_url () . '/wp-admin/';
else
$redirect_to = get_home_url () . '/startseite/';
}
wp_safe_redirect ($redirect_to);
exit;
}
else {
global $wp;
$login_url = get_home_url () . '/login/';
if (!strcasecmp ($login_url, $current_url) && is_user_logged_in ()) {
$redirect_to = get_home_url () . '/user-profile/';
//wp_safe_redirect ($redirect_to);
exit;
}
}
}
However, when entering proper user credentials and clicking the "log in" button in my custom login form, I seem to be getting forwarded to wp-login.php. This makes my above function redirect me to the custom login form, because apparently after clicking "log in" I am not yet logged in. How can I resolve this (apart from writing a custom login function that gets executed right after the "log in" button is clicked?)