Solution 1 :

get_the_excerpt() will get you just a teaser of your content. you can specify a post id if it’s outside a loop.

To get the blurred out version like the newspapers have on there site, we want our non-logged-in users to see a content teaser, the_excerpt() AND we don’t want them to see the full content, just a blurry version.

We can use wp_get_current_user()->roles to define an array of users that should be able to see the full post, and display a blurry version to the rest of them.

We can use the text-shadow css propriety to blur-out our content. And just in case, we want to limit the number of characters being displayed, so we will cut out our blurred content too using substr.

<?php
if ( have_posts() ) :
  while ( have_posts() ) : the_post();
    the_title( '<h1>', '</h1>' );
    the_excerpt();
    $roles = array( 'administrator', 'editor', 'subscriber' );
    if( array_intersect( $roles, wp_get_current_user()->roles ) ) {
      the_content();
    } else {
      echo '<span style="text-shadow:0 0 8px white;color:transparent;">' . substr( wp_strip_all_tags( get_the_content(), true ), 0, 650 ) . '</span>';
    };
  endwhile;
endif; ?>

Here is our result:

enter image description here


Learn more

Problem :

I want to display only part of a post.
The markup of my content looks like this:

<h4 id="content-blurb">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse pretium eros vitae nunc efficitur efficitur. Nulla maximus dolor at diam hendrerit auctor.</h4>
Nam fringilla, lacus eu tincidunt semper, erat arcu aliquam lectus, nec egestas velit neque quis tortor. Fusce bibendum erat nec eleifend sagittis.

I know I can get all of the post content with get_the_content(). I also know that I can count the words and extract it that way, but I want to able to pull it out using the ID tag so that it will still work if I change the content.

By