Redirect wp-login.php Page to Different URL

Only couple of months back one of my site started getting whole lots of traffic. At some point I started realizing that people are trying to log into my site. I had “Wordfence” and few other plugins installed on my WordPress site to monitor the login and logout activity. Even though the plugin did it’s job but I could see that attacks are coming in from all around the world. They were trying to login with various user name and password. However Wordfence blocked all of them after three failed attempt to login and I used to get Wordfence generated report to my mailbox.

There were times when I used to get well over 50-60 mails from Wordfence everyday. Now, we all WordPress users already know that “wp-login.php” file is the default login page for all WordPress based sites. So, I decided to shut down the log-in page for sometime and see how it goes. So, I came up with the following code, which basically redirects every single user who wants to go to wp-login.php page to my home page.

<?php
function redirect_login() {
   global $pagenow;
      if( 'wp-login.php' == $pagenow ) {
         wp_redirect('https://www.yourdomain.com/');
      exit(); } }
add_action('init','redirect_login');
?>

Right after adding this code to my theme’s functions.php file, I stopped getting any email from Wordfence. However, unfortunately I couldn’t even login but I was happy to know that my site is secured (at least for sometime). If you are also facing the same problem, you can use this snippet code.

Note: Please remember that using this snippet code will block your login page. Only way to get your login page back is to download your theme’s functions.php file manually and deleting the snippet code from functions.php file. Unless you have FTP access and know pretty well that what exactly you are up to, I wouldn’t recommend using this snippet on your site. However, this snippet could be your life saver, if your site gets attacked by hackers or started getting 50-60 mail a day from security plugins. It’s your call end of the day. Good luck.

Today In History

  •  
  •  

Comment

Leave a Reply

Note: Convet HTML, PHP, JavaScripts from Postable, before posting from comment section.
License: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution. Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.