add_action( 'get_header', 'redirect_anonymous_to_front_page', 100 );
function redirect_anonymous_to_front_page() {
if ( ! is_user_logged_in() && ! is_front_page() ) {
wp_redirect( home_url() );
exit;
}
}