How to get the unfiltered excerpt, without […] or auto-excerpting

The standard way of getting an excerpt is to use the_excerpt() or get_the_excerpt() template tags. I am trying to get just the actual content of the Excerpt field.

If there is an excerpt, I want to display it in full (without being abridged or appending […]). If there is no excerpt, I don’t want anything to be displayed.

Is there a straightforward way to do this in WordPress?

Something like this:

$real_excerpt = ??? 

if ( $real_excerpt ) {
   echo $real_excerpt;
} // shouldn't show anything if there isn't a custom excerpt

2 s
2

Why don’t you use the global $post variable? It contains an object with the content as it is on the db row corresponding to that post. Here’s how to use it:

global $post; // If for some reason it's readily accessible, invoke it
if($post->post_excerpt != '') {
    echo($post->post_excerpt);
}

Or:

$my_post = get_post($post_id);
if($my_post->post_excerpt != '') {
    echo($my_post->post_excerpt);
}

Very simple, but let us know if you’re having trouble getting it working.

Leave a Comment