excerpt_length WordPress Filter Hook
The excerpt_length hook allows you to control how long the excerpt is on your WordPress site. This can be useful if you want to control how much content is displayed on your home page or other archive pages.
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. |