I’m working on a test site, https://academy.rezexpert.com, and I was trying to make my site private by redirecting all non logged-in users to the login page by adding the following code to my theme’s function.php file:

function redirect_user() {
  if ( ! is_user_logged_in() && ! is_page(array('login','register','lostpassword','contact-us' ))) {
    $return_url = esc_url( home_url( '/login/' ) );
    wp_redirect( $return_url );
    exit;
  }

}
add_action( 'template_redirect', 'redirect_user' );

After some testing, I’ve encountered an issue while I was trying to reset the password of my test user. After I click the link to reset my password, I’m being redirected to the login page. I’m trying to figure out how I could resolve this.

Since the reset password link is a dynamically generated link, it’s not something I could add to my list of pages as shown in the code extract above. I was checking the wordpress documentation and I’m not seeing anything helpful. Any help would be greatly appreciated.

Read more here: Issue encountered while trying to keep website private


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: