Allow non logged users to visit only login page and password reset page

You indicated that your login page is your home page. If you want all non-logged in users to then be directed to the home page to log in, you need to check a couple of things:

  1. Is the user logged in?
  2. Is the current page the home page?

You can do these things with is_user_logged_in() and is_front_page(). If these are not true, then you can use wp_redirect() to redirect the user to the home page.

Assuming your forgot password page is a “page,” you could use is_page() in your logic as well.

You’ll need to hook it to an action so that it fires late enough to allow checking the page, but early enough to still safely redirect the user (i.e. before headers are sent). template_redirect is ideal for this.

add_action( 'template_redirect', 'my_frontpage_redirect' );
function my_frontpage_redirect() {
    if ( ! is_user_logged_in() ) {
        if ( ! is_front_page() && ! is_page( 'my-password-reset' ) ) {
            wp_redirect( home_url() );
            exit();
        }
    }
}

Adjust the slug in the is_page() call according to whatever the page slug is for your password reset.