Setting a custom excerpt length in WordPress

Setting a custom excerpt length in WordPress is possible. With just these three lines of code inserted in your functions.php you can determine the desired length for your excerpts.

The snippet is basically a filter that checks the returned excerpts. And makes sure that they contain at least 30 words each.

Again you can modify this snippet as you want to fit your specific desired excerpt length. As you can see, in our case, it is set to 30 words.

PHP
//Setting a custom excerpt length
function wph_custom_excerpt_length( $length ) {
	return 30;
}
add_filter( 'excerpt_length', 'wph_custom_excerpt_length');