Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide wp-login.php as log-in and redirect it to a custom login page

I'm trying to hide the wp-login.php on my site so I installed the plugin Rename wp-login.php, I renamed it as log-in. Now I want to redirect it to my custom login page so the default login form of wordpress is totally hidden. Is there a way to accomplish this? I have already tried a redirection plugin and the code below however it only supports the wp-login.php and not my new login url:

function redirect_login_page(){

// Store for checking if this page equals wp-login.php
$page_viewed = basename( $_SERVER['REQUEST_URI'] );

// permalink to the custom login page
$login_page  = get_permalink( '10' );

if( $page_viewed == "wp-login.php" ) {
    wp_redirect( $login_page );
    exit();
}
}

Is there a way to do this without actually altering the wordpress base files?

like image 285
aj noguerra Avatar asked Mar 29 '16 10:03

aj noguerra


People also ask

How do I redirect a WordPress login page?

Setting Up Login Redirect by User Role in WordPress Simply click the 'Add New' button in the 'Redirection Rules' section. Then, select the 'User Role' condition from the 'Rule Condition' drop down and choose the user role from the drop down list.


1 Answers

Try this

add_action('init','custom_login');
function custom_login(){
 global $pagenow;
 if( 'wp-login.php' == $pagenow ) {
  wp_redirect('http://localhost/wordpresstest/blog/');
  exit();
 }
}
like image 51
krunal sojitra Avatar answered Oct 29 '22 16:10

krunal sojitra