wp_trim_words is trimming by character instead of by words


I’m using WordPress 3.9.2, and having trouble with the wp_trim_words function. It seems to be cutting the string down to X characters instead of X words.


Put the following in a template file:

$str = "Imagine discovering a secret language spoken only online by a knowledgeable and learned few. Over a period of weeks, as you begin to tease out the meaning of this curious tongue and ponder its purpose, the language appears to shift in subtle but fantastic ways, remaking itself daily before your eyes. And just when you are poised to share your findings with the rest of the world, the entire thing vanishes.";

$str_excerpt = wp_trim_words($str, $num_words = 5, $more = '...' );

echo $str_excerpt;

In my browser, I see the output as Imagi.... That’s not how it should function though, as far as I read from the docs:


This function trims text to a certain number of words and
returns the trimmed text.


$trimmed = wp_trim_words( $text, $num_words = 55, $more = null);

Is there a setting or perhaps something in the theme I’m using that’s causing this behavior?

Banjer 3 years 2020-03-30T04:51:16-05:00 0 Answers 120 views 0

Leave an answer