Filter Hook since 2.7.0
excerpt_length
Controls the auto-generated excerpt word count
Description
excerpt_length only affects auto excerpts, not the Excerpt box in the editor. Return an integer word count.
When it runs
When WordPress generates an excerpt from post content because no manual excerpt exists.
Signature
apply_filters( 'excerpt_length', int $number );Parameters
$numberint — Word count. Default 55.
Examples
Basic
add_filter( 'excerpt_length', function( $length ) {
return 30;
} );Show 30 words in generated excerpts.
Real case
add_filter( 'excerpt_length', function( $length ) {
return is_search() ? 40 : 20;
} );Vary excerpt length by context — longer on search results, shorter elsewhere.
Common Use Cases
- Shorten excerpts for card layouts
- Lengthen excerpts for search results
- Vary length by post type
- Control reading time estimates
Common mistakes
- Expecting this filter to trim a manual excerpt — it does not
Related hooks
FAQ
Why did my excerpt_length change do nothing?
The post already has a manually written excerpt, or the theme calls a hardcoded wp_trim_words() instead of get_the_excerpt() — this filter only affects the auto-generation path.
Source: wp-includes/formatting.php