apply_filters( 'excerpt_length', int $number )
Filters the maximum number of words in a post excerpt.
Parameters
- $number
-
(int) The maximum number of words. Default 55.
More Information
Use this filter if you want to change the default excerpt length.
To change excerpt length, add the following code to functions.php
file in your theme adjusting the “20” to match the number of words you wish to display in the excerpt:
function mytheme_custom_excerpt_length( $length ) { return 20; } add_filter( 'excerpt_length', 'mytheme_custom_excerpt_length', 999 );
Make sure to set the priority correctly, such as 999, otherwise the default WordPress filter on this function will run last and override what you set here.
Source
Changelog
Version | Description |
---|---|
2.7.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/hooks/excerpt_length