Hide everything on site for visitors except specific page IDs

If you want to show a message, use this code in your functions.php file-

function se_236335_hide_content( $content ){
    $pages = array( 8, 26, 35 ); // allowed page IDs
    if( ! in_array( get_the_id(), $pages ) ){
        return 'Message here..';
    }
    return $content;

}
add_filter( 'the_content', 'se_236335_hide_content' );

If you want a page redirection, use this-

function se_236335_redirect(){
    // allowed pages IDs
    $p1 = 9;
    $p2 = 11;
    $p3 = 35;
    // redirect location
    $location = 9;

    if( ! is_page( [ $p1, $p2, $p3 ] ) ) {
        wp_redirect( get_permalink( $location ) );
        exit();
    }
}
add_action( 'wp', 'se_236335_redirect' );