Working With Excerpts

An excerpt is a summary of your blog post, this is an optional feature in WordPress and can be used in circumstances where you would only like to display a teaser of a post rather than the full article.

You can also set your RSS feeds to display this summary rather than the full post, which may entice people to come over to your blog to read the full piece. (In your Admin Panel under Settings > Reading.)

One of the beautiful parts of excerpts is that fact you can actually customize them to suit your needs, so I will show you a couple of ways you can do this.

The following snippets take place inside your functions.php file, so backup before we start!

Change The Excerpt Length

You may want your excerpts to be longer or shorter than the default, so what we can do is tell WordPress to display a custom count of words, open functions.php and add the following:

function new_excerpt_length($length) {
return 30;
}
add_filter('excerpt_length', 'new_excerpt_length');

This snippet will limit your word count in your excerpt to 30 words, by altering this figure you can define the word count shown.

So for example you only want 15 words to show:

function new_excerpt_length($length) {
return 15;
}
add_filter('excerpt_length', 'new_excerpt_length');

Change […] At The End Of The Excerpt

This one I frequently get asked, by default WordPress puts […] at the end of an excerpt, so to change this you need to place the following inside of your functions.php file:

function new_excerpt_more($more) {
return 'YOUR TEXT HERE';
}
add_filter('excerpt_more', 'new_excerpt_more');

Or you can link to the article itself like so:

function new_excerpt_more($more) {
return '<a href="'. get_permalink($post->ID) . '">' . 'Read More' . '</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

You Might Also Like