How to Create Excerpts in WordPress

How to Create Excerpts in WordPress

WordPress excerpts are handy if you wish to display a series of posts in a single page. When multiple posts are shown, it is easier for your readers to find what they want by only giving them a summary of each post. You can enable this post summary functionality by using the WordPress “excerpt” command. You can use this feature to increase your page views, to avoid duplicate content and to decrease page load time.

For the following pages excerpts are necessary because you need to display many posts in a single page:

WordPress blog homepage: Your most recent posts.

Category page: All posts belonging to the selected category.

Tag page: All the posts containing the selected tag.

Archive page: All posts published during the selected date.

Search results page: All posts and pages matching the search query.

You can set the maximum number of posts that are shown in these pages by going to Settings >> Reading and changing the number on the “Blog pages show at most” option.

Reading Settings

Enable WordPress Excerpts

If the feature is not available in your WordPress theme, you need to enable it by going into the index.php file of your theme and finding the line that contains the WordPress command the_content. Take the existing line:

<?php the_content(); ?>

And replace it with the following:

<?php the_excerpt(); ?>

This will style your blog so that it only shows text summaries when there are multiple posts, but shows the entire document for single posts or single pages.

How to get stylish WordPress excerpts

Add Background Images to Excerpts

You can add background images to the top, bottom, or side of each excerpt, depending on your current WordPress theme. However, there are certain standards that are adhered to by most themes. In particular, each post is usually summarized in a post class. If that post is an excerpt, it will further be summarized within an excerptcontent class. Just add the following styles into the style.css file of your current WordPress theme to set a side border graphic and a top background graphic.



Add Thumbnail Images to Excerpt

To add thumbnail images to WordPress excerpts, you need a function that extracts the first image from your posts. Add the get_first_image function mentioned below to your theme functions.php file.


Now call this function from your WordPress theme. Add the code below, right above the_excerpt command, in your theme index.php file.


It will add a right-aligned image to each post excerpt with the size at 200px by 200px. The code in your index.php file will now look like this –


Resize the Images in Your WordPress Excerpt

To resize the image and maintain its aspect ratio, add the code to your functions.php file:


$image is the image file or url.

$alt is the alternate text to use.

$newWidth and $newHeight are the new width or height you want to resize the image to.

Only one of these parameters will be used to resize the image. If $newWidth = 0 then $newHeight will be used to resize the image. Otherwise, $newWidth will be used.

The resize image function will return the HTML string for the input image, at the proper size. If the image cannot be found, a NULL string is returned. Finally, you just need to call this resize_image function from your theme. Replace the previous call to get_first_image in your index.php file with the code below.


Here is what the final index.php file looks like, instead of the original the_content command.


If you have trouble following through the above instructions, you can just set it up with your existing theme and plugins.

Custom Excerpts:


You can write custom excerpts for your posts from your WordPress admin panel and have them displayed in your theme. If you do not write a custom excerpt, then WordPress automatically takes the first 55 words from your post and displays them in an excerpt with ellipses.

Auto Excerpt Everywhere:

auto excerpt

Just activate the plugin Auto Excerpt Everywhere and it will automatically show the_excerpts in your homepage, archives and search results. It tries to display your custom excerpt text and if doesn’t find it, it will show an automatically generated excerpt. You can also define excerpt length, customize the read more link and attach a thumbnail.

It allows you to:

  • Turn excerpts on
  • Control the length of excerpts
  • Change the “Read more” text
  • Control thumbnails – off/on plus size control


Community-based and focused on all things WordPress!

Leave a Reply

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

How to Create Excerpts in WordPress

by WPSolution time to read: 3 min