How to Display Post Excerpts in WordPress Themes

In any WordPress magazine or blog’s home page we see lots of posts with
summery of that post. The texts we see in the home page actually comes from the post content. But we just see few words of the post content. In WordPress we called it excerpt. So how can you add this cool feature in your website.

Well the first thing is add this code in your functions.php.


// 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');

The first function return the length of the text that we want to show and
the second funciton returns how many dots we want to show after the text. You can change it both as you want.

Display Excerpt

Ok now simply add this funciton into your post loop and it work perfectly.


<?php the_excerpt(); ?>

Pretty easy yeah ??

Leave a Reply

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