Sometimes you need quick solutions for different WP needs. I am sure you have library full of reusable and codex quality snippets. Came across this which came through in a pinch.
If you have a layout that is dependent on copy behaving within a certain word count this can help. Whether it’s the post title, the post content, or the post excerpt, this excerpt can even if just temporarily.
echo wp_trim_words( get_the_title(), 5); // for the post title echo wp_trim_words( get_the_content(), 20); // for the post content echo wp_trim_words( get_the_excerpt(), 10); // for the post excerpt