Categories
Uncategorized

How to Alter WordPress Excerpt Length

To change the default length of a WordPress generated excerpt, we need to filter the output of the WordPress the_excerpt() function.

Add the following to your functions.php file.

If you theme does not have a functions.php file, you can find starter code here:

Be sure to change all instances of the word THEME in the code below to your theme name (in lower case).

Inside the THEME_excerpt_length function, you can change the returned number to have the excerpt be any length you want.

// Change all instances of THEME to your theme name.

function THEME_excerpt_length(){
  return 20;
}

add_filter('excerpt_length', 'THEME_excerpt_length');