How to Display Post Excerpts in WordPress Themes

Posted on January 17th, 2010 by in Themes | 21 Comments  
How to Display Post Excerpts in WordPress Themes

Some of our users wanted us to post a tutorial on how to display Post Excerpts in WordPress Themes. This is a very simple tutorial that anyone can implement and take advantage of this built-in feature. The benefit of implementing this tutorial is that it decreases page load time and it increases the pageview count.

How does it Decrease Page Load Time?

If you write long posts like best practices of contact forms or must have iphone apps for bloggers which has a lot of images, then having them load on one page can significantly impact your page load time. By adding this technique, you can simply show a mini description of the article and let user view the post on single post page.

How does it Increase Page View count?

Sometimes users just read the post on the category page if you don’t use the excerpt. By adding it this way, they will go to the original post. That is 2 page views instead of 1. It also encourages users to make a comment on the post because comment form is also on this page and they don’t need to load a separate page to make a comment.

Tutorial

Open your index.php file, archive.php file, and category.php file. Now some of you might not have all these files in your template, so just open the ones that you do have.

Find the following code:

<?php the_content(); ?>

And replace it with:

<?php the_excerpt(); ?>

Now you can write custom excerpts for your posts from your WordPress admin panel and have it displayed in your theme.

Add Post Excerpts in WordPress

If you do not write a custom excerpt, then WordPress automatically takes the first 55 words from your post and put them in an excerpt with elipses and display it. You can change the word limit starting from WordPress 2.9. If you want to change the word limit open your functions.php file and add the following function:

// Changing excerpt length
function new_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');

// Changing excerpt more
function new_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');

If you want to see this code working live, just click on any of our categories from the navigation menu and you will see that we do not display full posts.

About

Editorial Staff at WPBeginner mainly Syed and David.

Post comment as twitter logo facebook logo
Sort: Newest | Oldest
LarryHorne 5 pts

I can't find the referenced code in the index.php file for the theme Twenty Eleven 1.2 Can you direct me to where the line can be changed to only display summaries?

HemantKokcha 5 pts

I am trying to get excerpt but i cant get excerpt by both of your method so tell me correctly how wll i get excerpt in traction theme.

wpbeginner 50 pts moderator

HemantKokcha There is only one method... changing the_content to the_excerpt... The other function is to controlling excerpt length and the excerpt read more. If its not showing in your theme, then perhaps try contacting the theme author. Because this is the only way of doing it.

clwdk 5 pts

Hi there,

I am using the newest version of the twenty ten theme and am not sure where to change the &lt;?php the_content(); ?&gt; to &lt;?php the_excerpt(); ?&gt;. There is nothing in the index.php as far as I can see. Am I overlooking something? Thanks for any help you can give me.

CARL

wpbeginner 50 pts moderator

clwdk You would need to change the loop.php file for the archive.

Ibadullah 5 pts

It keep showing me the number I add in post excerpt instead of post content!

wpbeginner 50 pts moderator

Ibadullah That is the whole point of this article.

Ibadullah 5 pts

wpbeginnerIbadullah I am saying when I add the number in post excerpt - I just see the same number on main page. such as I type 50 in the post excerpt field it show Category name : APPLE and instead of content it show number 50

wpbeginner 50 pts moderator

Ibadullah You have to add this code in your theme's functions.php file. It should work perfectly fine because this is the way to do it, and we are doing it on our site.

Great - thanks. Was looking for a simple solution. How do you include a Read more... link after the excerpt also though?

Thank you for the article. I made the changes in all 3 documents and nothing changed. All of the posts on the blog I am working on were imported from Blogger, could that be an issue or perhaps the theme itself? I am stumped!

Nope that can't be the issue. By changing to the_excerpt it would automatically generate the excerpt.

I can't seem to find any files containing "php" anywhere on my wp dashboard.

I'm using dreamhost and the wp 2010 theme. The only files I can find that allow me to edit code are .css files.

I'm going crazy trying to find a way to create excerpts!

Look under Appearence > Editor (There you will find the file)

thanks! just changing the index.php 'content' to 'excerpt' did the trick...

My acquaintance is asking for this and I remember to ever saw it here. Thanks, I will forward this to him.

I understand the excerpt thing but how do I then get it to show the image thumbnail along with the excerpt?

By adding the WordPress Thumbnail there: http://www.wpbeginner.com/wp-themes/how-to-add-pos...

You would have to add styling to match your theme.

Great, I was just looking for an easy way to make use of the excerpts field and be able to define a small intro for each post to be displayed. Thanks a lot.

Tweets about us: