WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/has excerpt

Description

Whether the current post has a custom excerpt.

Usage

<?php has_excerpt$id ); ?>

Parameters

$id
(integer) (optional) Post ID
Default: Current post ID

Return Values

(boolean) 
True if the post has an excerpt, false if it does not.

Examples

<?php
// Get $post if you're inside a function
global $post;

if ( has_excerpt( $post->ID ) ) {
    // This post has excerpt
} else {
    // This post has no excerpt
}
?>


Other Use

When you need to hide the auto displayed excerpt and only display your post's excerpts.

<?php if ( ! has_excerpt() ) {
      echo '';
} else { 
      the_excerpt();
}

Replace auto excerpt for a text or code.

<?php if ( ! has_excerpt() ) {?>
    <!-- you text or code -->
<?php } ?>

Changelog

Since: 2.3.0

Source File

has_excerpt() is located in wp-includes/post-template.php.

Related

See also index of Function Reference and index of Template Tags.