Redirect if current user is logged out and current page is /my-account

Fixed!

I had to use the wp hook which means that the redirect function is only run once the whole page is loaded! Sweet 🙂

add_action( 'wp', 'redirect' );
function redirect() {
  if ( is_page('my-account') && !is_user_logged_in() ) {
      wp_redirect( home_url('/login') );
      die();
  }
}