How to Trim WordPress Text / Words with wp_trim_words()
(Last Updated On: July 10, 2014)
WordPress introduced a new function wp_trim_words(). This is helpful to trim the text to a specific number of words. You can use this function for the_title(), the_content() and the_excerpt() in your post’s loop. Put the following code in your loop.
//For post title echo wp_trim_words(get_the_title(), 50); //For excerpt echo wp_trim_words(get_the_excerpt(), 50); //For content echo wp_trim_words(get_the_content(), 50);
Note: wp_trim_words() is supported in WordPress 3.3 and 3.3+.