WordPress: How to Show Excerpts on the Home Page
Posted onIt’s rare to find a theme that gets everything just right for you. Sometimes the color combinations might be a bit off, or the font not quite the right size. There are hundreds of little customizations that you can make to a theme in order to mold it perfectly to your tastes. One such example is the display of “excerpts” instead of the full content of an article on the homepage and archive type URLs. Some themes will have excerpts built into specific types of pages such as search results. In order to replicate the style on the homepage, you’ll have to modify the PHP code of your theme depending upon which page is being used to render the content. Here’s how to show excerpts in WordPress using this technique as well as with a plug-in.
Even if you take the default twentyfourteen theme that ships with WordPress, it displays the entire post contents on the homepage as shown below:
I’ll be using this theme as an example for the steps that follow.
Using the Excerpt Functionality
The first thing to do is to find out which PHP page is responsible for rendering content on your homepage. WordPress has a hierarchy of templates that it uses. On your administration dashboard, click the “Editor” sub menu under “Appearance”. This will display a list of PHP files down the right-hand side. If you can find one called home.php, that is the one that is most likely to generate the content for the homepage. Otherwise, index.php is the default template.
However, depending on the structure of your theme there is no easy way to ascertain beforehand which page will contain “The Loop”. For example, the twentyfourteen theme tucks away the contents of the loop within content.php. If you’re lucky, your theme will have an easy to find PHP page containing the code necessary for displaying the homepage.
The function that you’re going to use to display the excerpt is called “the_excerpt”. In your homepage code, search for a line containing the function “the_content” which outputs the entire post. We need to replace it with “the_excerpt” only for the homepage. The twentyfourteen theme is confusing in the sense that all the code is mixed up so we have to use conditional tags to generate the excerpt only on the homepage.
Code similar to the one below should do the trick:
if (is_home()) { the_excerpt(); } else { // Code for the entire content goes here }
As shown below, I have added a check for the homepage in addition to one for the search results that display excerpts in content.php for the WordPress theme twentyfourteen. Here’s what the final result looks like for the same post shown in the beginning:
But if you don’t want to mess around with code, there’s a neat plug-in that does the job for you.
Auto Excerpt Everywhere
The Auto Excerpt everywhere plugin automatically allows you to configure excerpts in all places where the full post contents will normally be shown. In addition, it also provides you with the ability to select the number of characters in the excerpt, thereby providing a great deal of flexibility and customization.
After downloading and installing the plug-in, you can configure the options either directly from the plug-in screen, or from the submenu under the “Settings” menu item in the WordPress administration dashboard. Here’s what the options screen looks like:
As you can see, it also allows you to disable excerpts on the homepage if you want but enabling them everywhere else including the category pages, archives, and search pages. A nice addition is the ability to configure thumbnails and select where you want them to show in relation to the excerpt.
Depending on theme complexity, you might decide to make the modifications to the code yourself or use the plug-in . If your theme is straightforward and easily configurable, use the former approach. Otherwise, the latter option might be the smarter one.