Disabling automatic teasers

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.

Read More

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.

Related posts

Leave a Reply

2 comments

  1. Try using $post->post_excerpt instead:

    // globalize $post, just in case
    global $post;
    // find out if the post has a defined excerpt
    $data = $post->post_excerpt;
    // If so, output something
    if ($data) echo "<div class='excerpt'>$data</div>";
    

    This method will bypass the auto-excerpt generation inherent in get_the_excerpt().

    EDIT

    By popular demand, the same code, using has_excerpt():

    // find out if the post has a defined excerpt
    $data = ( has_excerpt() ? get_the_excerpt() : false );
    // If so, output something
    if ($data) echo "<div class='excerpt'>$data</div>";
    
  2. A method I use which dosen’t require using global $post; is to use this snipit right before the_excerpt() inside the loop.

    <?php
    if (!has_excerpt()) {
             the_content(); //show the content if no excerpt
     } else {
             the_excerpt(); //else show excerpt
    }
    ?> 
    

    If you only wanted to show the_excerpt() if it existed and not the_content() at all you could use:

      if(has_excerpt()){
              the_excerpt();
      }