Wordpress

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:

1 <?php the_content(); ?>

And replace it with:

1 <?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:

01 // Changing excerpt length
02 function new_excerpt_length($length) {
03 return 100;
04 }
05 add_filter('excerpt_length', 'new_excerpt_length');
06
07 // Changing excerpt more
08 function new_excerpt_more($more) {
09 return '...';
10 }
11 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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s