I have a custom theme that displays the excerpt:
$data = get_the_excerpt();
if ($data) echo "<div class='excerpt'>$data</div>";
if nothing is entered in the excerpt field in the post editor, WordPress will automatically use the auto-generated teaser.
I would like to get rid of this behaviour. Is there any way to do so? At the moment, I have to entere a space into the excerpt field of every post to prevent the automatic teaser from showing.
Try using
$post->post_excerpt
instead:This method will bypass the auto-excerpt generation inherent in
get_the_excerpt()
.EDIT
By popular demand, the same code, using
has_excerpt()
:A method I use which dosen’t require using
global $post;
is to use this snipit right beforethe_excerpt()
inside the loop.If you only wanted to show
the_excerpt()
if it existed and notthe_content()
at all you could use: