Tag: the_excerpt

Easily Add Page Excerpts in WordPress

Ever need to add an excerpt field for WordPress when working with pages? There is an easy, one line way to do this (no plugin needed). Simply add this to your theme’s functions.php file:

add_post_type_support( 'page', 'excerpt' );

Once you have that in place – you can then use the WordPress the_excerpt() function to show the excerpt within the theme.

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.