Answer:
// Redirects visitors to the login page if they are not logged in and if they are on either example-page-1, example-page-2 or example-page-3
// After they login they will be redirected back to the page they were on before login.
// The login URL will contain the URL to your login page + the redirect_to Query String with the slug for that page.
// https://www.example.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.example.com%2Fexample-page-1%2F
function custom_login_redirect() {
if ( ! is_user_logged_in() && is_page( array( 'example-page-1', 'example-page-2', 'example-page-3' ) ) ) {
wp_safe_redirect( wp_login_url( get_permalink() ) );
exit();
}
}
add_action( 'template_redirect', 'custom_login_redirect' );