How to Change Post Excerpt Length in WordPress?

The default post excerpt length is 55 words in WordPress.

You can use the WordPress filter ‘excerpt_length‘ to change the default excerpt length. It allows you to filter the maximum number of words in a single-post excerpt.

function maverick_change_post_excerpt_length($length)
 return 20;
 add_filter('excerpt_length', 'maverick_change_post_excerpt_length', 999);