Change the default excerpt length in WordPress

This is another useful snippet for modifying the length of the excerpt (in amount of words).

Drop this in your theme’s functions.php and modify the length as you wish:

/*  Excerpt length
/* ------------------------------------ */
function alx_excerpt_length( $length ) {
	return 30;
add_filter( 'excerpt_length', 'alx_excerpt_length', 999 );

In this case I set the amount of words to 30.

Written by:Alexander Agnarson

1 Response

  1. Irene says:

    Hello, thanks for this post. I am using the Anew – with Child – theme and I wonder how you can adjust ‘the_excerpt’ that includes HTML formatting (2 paragraphs for instance).

Leave a Reply

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