Fixing Excerpts in WordPress Themes

Trouble getting your posts page to display only excerpts? You are not the only one. Many WordPress themes don’t actually support the feature – even the bundled and default WordPress themes seem lacking (notably, the Twenty-Thirteen theme that this site uses).

Clicking on a category or index page shows the full posts, and is a trouble to scroll through. This is especially so for long posts.

Yuck. Full length posts (even short ones) kind of ruin the purpose of archive directories.

The cause in my case? Seems like WordPress supports “Only displaying Excerpts for Search” in its Twenty-Thirteen theme, as show in content.php:

.
.
.
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
.
.
.

The solution is a simple one-liner luckily. Replacing is_search() with !is_single() checks if the post or page is being displayed on another page, and won’t show the full content unless it is being viewed directly:

.
.
.
<?php if ( !is_single() ) : // Only display Excerpts, except When Viewing Post>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
.
.
.

WordPress needs to vet their themes a bit better! This fix works as required, and I get a nice excerpt on all my category and index pages:

Excerpts: short, and to the point!

Now I have happy excerpts, and to you I wish Happy WordPress-ing!

Leave a Reply

Your email address will not be published. Required fields are marked *