Languages: English • Italiano • 日本語 (Add your language)
This function trims text to a certain number of words and returns the trimmed text.
<?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ?>
An example which strips formatting:
<?php echo wp_trim_words( get_the_content(), 40, '...' ); ?>
wp_trim_words() is located in wp-includes/formatting.php
.
Also handy for clean string export: wp_strip_all_tags function