excerpt_length
Sets how many words WordPress keeps when it creates an automatic excerpt from a post's content. The default is 55.
When it fires
WordPress applies excerpt_length in wp_trim_excerpt() when a post has no manual excerpt and one has to be cut from the content. The Latest Posts block applies it too.
Excerpts typed into the Excerpt box are never shortened by this filter.
Parameters
$numberint |
The maximum number of words. Default 55. |
|---|
What to return
An integer: the number of words to keep.
Example: Use 30-word excerpts
add_filter( 'excerpt_length', function ( $number ) {
return is_admin() ? $number : 30;
}, 20 );
Good to know
- In block themes, the Post Excerpt block uses its own word limit setting and overrides this filter while it renders.
- Use a priority above 10 if your theme sets its own excerpt length, so yours runs last.