Tutorials

How to disable or redirect the default WordPress login page (wp-login.php)

If you have a custom WordPress login form or you do not want anyone to access the default login form, due to security reasons or any other reason, you can set a redirect for the wp-login.php page.

You could set a redirect simply in the .htaccess or the site's Nginx config file, but this will break the ability to login, logout and the forgot password feature. This is so beacuse the wp-login.php script handles all these features.

In your theme's folder, you will find the 'functions.php' file. You need to add the following code in the functions file :

add_action('init','custom_login');
function custom_login(){
 global $pagenow;
 //  URL for the HomePage. You can set this to the URL of any page you wish to redirect to.
 $blogHomePage = get_bloginfo('url');
 //  Redirect to the Homepage, if if it is login page. Make sure it is not called to logout or for lost password feature
 if( 'wp-login.php' == $pagenow && $_GET['action']!="logout" && $_GET['action']!="lostpassword") {
     wp_redirect($blogHomePage);
     exit();
 }
}

Copyright © 2018 WPOven