apply_filters( 'excerpt_length', int $number )

Filters the maximum number of words in a post excerpt.


Description


Parameters

$number

(int) The maximum number of words. Default 55.


Top ↑

Source

File: wp-includes/formatting.php

View on Trac


Top ↑

Changelog

Version Description
2.7.0 Introduced.

Top ↑

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.