Change the_excerpt Length and Ending

Change the_excerpt Length and Ending

Using WordPress – there are some times when you want to use the_excerpt but you do not want to show the default 55 words and/or show the […] after those 55 words.

Change the Length

Instead of only showing the default 55 words where you want to change it to something longer or shorter. To change this – just add/modify this in your functions.php file:

add_filter('excerpt_length', 'sdac_excerpt_length');
function sdac_excerpt_length( $length ) {
	return 75;
}

In that code example – I am setting the length to be 75 words.

Change the Ending

Instead of showing the default […] after the excerpt – you can omit that or change it. To change this – just add/modify this in your functions.php file:

add_filter('excerpt_more', 'jappler_excerpt_more');
function jappler_excerpt_more( $more ) {
        global $post;
	return '... <a>ID ).'"&gt;Read More &raquo;</a>';
}

In that example – I added a read more which links to the post permalink. (This filter is available with WordPress 2.9+)

Hopefully these examples will help a little bit the next time you want to use the excerpt but wished it was easy to change the output.

Leave a Reply

Your email address will not be published.
*
*

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