Notes

Custom Excerpt or Entire Post

WordPress ships with two different ways to get a short version of a post: a manual excerpt typed by hand, and an automatic one generated from the content. the_excerpt() already prefers the manual one when it exists — but sometimes what you actually want is the reverse split: a manual excerpt where one was written, and the full post everywhere else. That’s what this conditional is for.

<?php if ( $post->post_excerpt ) {
	the_excerpt();
} else {
	the_content();
}
?>

1. Use has_excerpt() instead of touching $post directly

Reaching into $post->post_excerpt works, but it depends on the global $post being the one you mean, and it’s checking a raw database field instead of asking WordPress the question directly. has_excerpt() is the same check core uses internally, and it accepts an optional post ID:

<?php if ( has_excerpt() ) : ?>
	<?php the_excerpt(); ?>
<?php else : ?>
	<?php the_content(); ?>
<?php endif; ?>

2. Where the manual excerpt field actually is

In the block editor it’s the Excerpt field in the Summary panel of the post sidebar — visible by default, no setup required. In the classic editor it’s a box that has to be turned on first, from Screen Options at the top of the edit screen. Either way, if that field is left blank, has_excerpt() returns false and the conditional falls through to the_content().

3. A hybrid: manual excerpt, or a trimmed fallback instead of the full post

the_content() dumps everything — images, embeds, shortcodes, all of it. On an archive or a card layout that’s usually too much. The more common version of this pattern shows the manual excerpt in full, but falls back to a short, word-trimmed slice of the content instead of the whole thing, with its own link back to the post:

<?php if ( has_excerpt() ) : ?>
	<p><?php echo esc_html( get_the_excerpt() ); ?></p>
<?php else : ?>
	<p><?php echo esc_html( wp_trim_words( get_the_content(), 40 ) ); ?>
	<a href="<?php the_permalink(); ?>">Read more</a></p>
<?php endif; ?>

4. Changing the auto-generated excerpt itself

The two filters below only touch the excerpt WordPress generates — its length in words, and the trailing text that marks it as cut off. A manual excerpt is never touched by either filter; whatever was typed into that field is shown exactly as written, at whatever length it happens to be:

<?php
add_filter( 'excerpt_length', function () {
	return 40;
} );

add_filter( 'excerpt_more', function () {
	return ' …';
} );
?>

Which version to reach for comes down to where it’s used: the plain has_excerpt() check on a single post template, the trimmed hybrid on an archive or card grid, and the two filters when the goal is to change get_the_excerpt() sitewide rather than override it post by post.