Hide content and functions from specific user roles

If you’re new in WordPress dev, I would recommend this plugin https://wordpress.org/plugins/members/, there is an option to allow you to disable content based on User role, you can also easily creating role with the plugin.

As for your question: if you don’t want the user with role subscriber for viewing content, I’m using twentysixteen theme as an example

// Start the loop.

if( have_post() ) :
    while ( have_posts() ) : the_post();

        /*
         * Include the Post-Format-specific template for the content.
         * If you want to override this in a child theme, then include a file
         * called content-___.php (where ___ is the Post Format name) and that will be used instead.
         */
        if( current_user_can( 'edit_posts' ) ) :
            // can accessed by contributor and the others but not subscriber
            get_template_part( 'template-parts/content', get_post_format() );

        endif;



    // End the loop.
    endwhile;
endif;

‘edit_posts’ role is a capability which subscriber do not have, you can view more about roles and capability chart here https://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table