Quick tip: Use wp_trim_words() to limit words in WordPress
WordPress 3.3 brought a handy little function with it in wp_trim_words(). An example use case is a height limited box like the one pictured, where you want to make sure that the title and excerpt don’t cause the text to overflow the box.
Using wp_trim_words() allows us to limit the title and excerpt, and anything else really, to a particular number of words. How practical a name. You can define the number of words to limit them to, and also define what you’d like the “more” text to be. My example just uses ellipses.
Below is a gist to show it in use. Everything but the use of wp_trim_words() is totally arbitrary, but there for fun.