WordPress: How to display excerpts instead of full posts on archive pages

In the WordPress dashboard under Settings –> Reading, there is an option that appears as if it would show summaries of each post on the main page, instead of full posts. Next to “For each article in a feed, show”, there are options for “Full text” and “Summary”.  This does not do what I thought it should. It turns out that WordPress does have a way of creating post excerpts, but you have to go into the PHP code in order to enable this.

According to this article on wpbeginner.com, the PHP edit would need to occur in index.php, archive.php, or category.php.

They recommend replacing this PHP code:

<?php the_content(); ?>

with this:

<?php the_excerpt(); ?>

However, for my theme I found that the file I actually needed to update was called content.php, found in the theme folder. In order to get excerpts instead of full posts on the main page I changed this line:

<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'hemingway-rewritten' ) ); ?>

to:

<?php the_excerpt( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'hemingway-rewritten' ) ); ?>

Now excerpts can be seen on the main “Home” page:
http://bluegalaxy.info/codewalk/

And on any other archive, such as the month of October:
http://bluegalaxy.info/codewalk/2017/10/

Category archive:
http://bluegalaxy.info/codewalk/category/pandas/

Tag archive:
http://bluegalaxy.info/codewalk/tag/iframe/

And search results:
http://bluegalaxy.info/codewalk/?s=Ubuntu

Leave a Reply