• Skip to main content
  • Skip to footer
HostingWiki

HostingWiki

  • Home
  • Guides
  • About

December 13, 2019 - Tutorial, WordPress

WordPress 101: How to Use the_excerpt() Function to Generate Post Excerpts

hostingwikieditorial

Excerpts are a great way to invite visitors to read your articles. Unfortunately, not all themes support this feature. But worry not! You can go around this little setback by inserting the_excerpt() function into your theme’s template files.

Although setting up the function will require you to do a little coding, I assure you it’s actually not that hard. Just follow the instructions in this article, and your site will display excerpts in no time!

Introduction to the WordPress Excerpt

An excerpt is a brief summary of your article that allows the readers to know what to expect from the post. Just like a teaser to a movie, it lets them decide whether they’re interested in reading the whole article or not.

If you’ve seen plenty of blogs before, chances are you have seen how excerpts look like. They usually appear in blog index pages, just like the one below:

An example of a WordPress excerpt.There are two methods that you can use to display excerpts on your WordPress page without having to use the_excerpt function:

  • Automatic excerpts. By default, WordPress will select the first 55 words (or more) of your article and use them as the excerpt.
  • Manual excerpts. If you prefer to create your own excerpt, you can do so by navigating to Posts -> Add New. Click Screen Option and tick the Excerpt box.
    Enabling excerpt though screen option.

After that, a new box named Excerpt should appear below your WordPress editor. Use this box to write custom excerpts.The excerpt container box.

How to Display Excerpts Using the_excerpt() Function

As mentioned before, some themes can’t display excerpts. As a consequence, your blog index pages will show the full content of each post instead of the summaries. Not so pretty, isn’t it?

To know whether your theme supports excerpts or not, go to Dashboard -> Appearances and look for the excerpt option under the post or layout settings.

Checking if your theme supports excerpts.

Do you find a similar option like the one shown above? If yes, simply tick the box and your excerpts will appear. However, if you don’t, get ready to insert the_excerpt function into the theme’s template file.

Unfortunately, because each theme is coded a little differently, there’s a chance that this method won’t work. So before we go on, don’t forget to create a backup first. You might also want to apply the function on a child theme so your changes won’t disappear when the theme is updated.

With that in mind, let’s get started! Here’s how you do it:

  1. Go to the theme template files. You can either do that from the WordPress dashboard (Appearance -> Theme Editor), or you can access the File Manager from your control panel (wp-content/themes/name-of-the-theme).
  2. Locate the_content() template tag in your theme files. This may be the most tricky part since each theme has it in different locations. Try to look for it in index.php, archive,php, or categories.php. Press CTRL + F to make the search easier. If you still can’t find it, try to search from the files under the template-parts section.
  3. Replace the_content() with the_excerpt(). Once you find the_content tag (there should only be one of them), just erase it and type in the_excerpt.
    Replacing the_content with the_excerpt in the content.php file.
  4. Save the file, and you’re all set. Click Update File and wait until it shows “File updated successfully”. Then, check out your site now – it should display excerpts with three little dots in a bracket at the end.
    The end result of how your excerpt will look like when the_excerpt() function is in action.

Wrapping Up

That was quite a ride, wasn’t it? But now that you have successfully edited your theme template files, your blog index page will no longer show a wall of text. Visitors will be happy to browse through your articles!

If you run into trouble when applying the_excerpt() function, feel free to drop a comment below.

Reader Interactions

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Footer

HostingWiki Logo

Site Links

  • Contact Us
  • Mission
  • About
  • Sitemap

Legal

  • Privacy Policy
  • Terms of Use
  • Cookie Policy
  • Contact Us
  • Mission
  • About
  • Sitemap

Additional menu

© 2021 HostingWiki is a Hostinger publication.