Redirecting Wordpress's Login/Register page to a custom login/registration page

I have a website, with a user system. I want to integrate wordpress's user system into that website's, but I still want to use the website's register/login pages. I don't want anybody to be able to login or register using Wordpress's login or registration forms. Instead, when they're try to access the login/registration pages in Wordpress, I want those pages to redirect them to my own login/registration pages.

Is there any way of doing this? I've tried Google, but all I could find was redirection AFTER the user logs in or registers, which is not what I want.

Thank you in advance.

Answers


For this you need to redirect login/registration page to your custom pages. So, Write this code in your functions.php file Under your activated theme folder. Pass your custom page path as a Argument.

 add_action('init','possibly_redirect');

function possibly_redirect(){
 global $pagenow;
 if( 'wp-login.php' == $pagenow ) {
  wp_redirect('http://google.com/');
  exit();
 }
}

To restrict direct access only for 'wp-login.php', without POST or GET request (useful for custom ajax login forms), I use the advanced function:

function possibly_redirect(){
  global $pagenow;
  if( 'wp-login.php' == $pagenow ) {
    if ( isset( $_POST['wp-submit'] ) ||   // in case of LOGIN
      ( isset($_GET['action']) && $_GET['action']=='logout') ||   // in case of LOGOUT
      ( isset($_GET['checkemail']) && $_GET['checkemail']=='confirm') ||   // in case of LOST PASSWORD
      ( isset($_GET['checkemail']) && $_GET['checkemail']=='registered') ) return;    // in case of REGISTER
    else wp_redirect( home_url() ); // or wp_redirect(home_url('/login'));
    exit();
  }
}
add_action('init','possibly_redirect');

The correct action hook is login_init that only fires on wp-login.php.

Here, no ?action=action-name is being requested, so it's the main login page:

add_action('login_init', function(){
    if( !isset( $_GET['action'] ) ) {
        wp_redirect( 'http://example.com' );
    }
});

For all requests, we can use a specific hook login_form_ACTION-NAME, ie, postpass, logout, lostpassword, retrievepassword, resetpass, register and login. Example:

add_action('login_form_register', function(){
    wp_redirect( site_url('custom-registration/') );
});

If you're making use of a custom login page, but still using wp_login_form(), be aware that the form will POST to wp-login.php, so you will want to check if $_POST is empty before redirecting.

function prefix_wp_login_redirect() {
  global $pagenow;  
  if( $pagenow == 'wp-login.php' && empty($_POST)) {
    auth_redirect();
    exit();
  }
}

You might be able to latch onto the login_head hook and issue a redirect there.


Need Your Help

Print out elements from an array with a comma between elements except the last word

java formatting

I am printing out elements from a array list, I want to have a comma between each word except the last word. Right now I am doing like this:

How to add external library in IntelliJ IDEA?

intellij-idea

I am trying to add external library (places it in the /libs directory) to my project. When I try to use the methods from that library, I see that they are in red color which means that the library ...