A simple function that sets the number of words returned when you call the the_excerpt function in WordPress. Add to functions.php and change the number on line 4 as needed.
function custom_excerpt_length( $length ) {
return 40;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );This uses the excerpt_length filter hook. Learn more in WordPress Hooks Explained.