I would like to redirect this page wp-login.php
to /login
page.
So when a user clicks on a link like this <a href="https://wordpress.stackexchange.com/wp-login.php">login</a>
, wordpress will redirect him to /register
.
I found this function and modified it :
add_action('init','custom_login');
function custom_login(){
global $pagenow;
if (( 'wp-login.php' == $pagenow ) && (!is_user_logged_in())) {
wp_redirect('/login');
exit();
}
I am not good with wordpress coding.
The redirection works fine, but the authentication seems to be broken.
When I enter my login/pass, the same page (/login
) reloads without being authenticated.
Any suggestion to fix the function for redirection ?
4 Answers
If you’re only concerned about login links displayed on your pages, you should be able to modify the URL by hooking the login_url
filter. This won’t redirect a user that types http://MYSITE/wp-login.php
directly into their browser, but it should affect the login links displayed throughout your site.
This is the example code from the login_url
Codex page:
add_filter( 'login_url', 'my_login_page', 10, 2 );
function my_login_page( $login_url, $redirect ) {
return home_url( '/my-login-page/?redirect_to=' . $redirect );
}