I created some custom login/registration template pages and now I want that every request to wp-login.php to be redirected to a custom url. Now I have something like this:
add_action('init','possibly_redirect');
function possibly_redirect(){
global $pagenow;
if( '/wp-login.php' == $pagenow ) {
wp_redirect('/login');
exit();
}
}
but it doesn’t work properly because when I click a logout link (in a meta widget) it will redirect me to the /login link and not doing logout. Do you have other method to do this in a safe or a better way ?
Thank you.
To restrict direct access only for ‘wp-login.php’, without POST or GET request (useful for custom ajax login forms), I use the advanced function:
Actually I found the right way to do this.
For redirect wordpress login to a custom url:
For redirect wordpress registration to a custom url:
I think the code is very simple to understand, basically you add hooks for login and register url’s and then use wp-redirect to redirect to a custom url. All requests to wp-login.php and wp-login.php?action=register will be redirected to the custom url’s you set.
I would recommend John’s answer, having
exit()
omitted. So, the code that is fully functional in my case is:It seems that the
exit()
is making it impossible for a user to login.Two things to note from the WP function reference for
wp_redirect()
…exit;
is indeed part of the usage, and$location
parameter is to be the “Absolute URI”, one including the protocol (http://
)Example of Absolute/Full URI:
http://www.example.com/blog/images/icecream.jpg