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:
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.
This will help to apply the excerpt_length on front end only.
Set the excerpt length based on a theme mod, through the Customizer.
Notes: This will display your excerpt text up to 30 words using excerpt_length filter. By default the number of words is 55.
Example:-
This will display your post excerpt up to 30 words.
This is useful to display different excerpt length on homepage, custom page template (where listing some custom post types).