Redirect users to a front end wp login page

Question

My theme allows me to create a front-end login form in a normal blog page. Now, I wish to redirect all the users to that page and not to wp-login.php. I have used the below code snippet.

function redirect_login_page(){
   $page_viewed = basename($_SERVER['REQUEST_URI']);
   // Where we want them to go
   $login_page  = 'http://localhost.com/login/';
   if( $page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {
     wp_redirect($login_page);
     exit();
   }
}
add_action('init','redirect_login_page');

But the problem is, it only redirects wp-login.php page. What if we place wp-admin, (e.g. http://localhost.com/wp-admin/) it does not redirect. Instead it takes to that wp-login.php page (which I do not want)

Any suggestions?

0
kalyan 2 months 0 Answers 11 views 0

Leave an answer