It is easy to use the PHP function. Take a look at this example:
function trim_text($input, $length) { // If the text is already shorter than the max length, then just return unedited text. if (strlen($input) <= $length) { return $input; } // Find the last space (between words we're assuming) after the max length. $last_space = strrpos(substr($input, 0, $length), ' '); // Trim $trimmed_text = substr($input, 0, $last_space); // Add ellipsis. $trimmed_text .= '...'; return $trimmed_text; }
Then you can pass the text using a function, for example:
trim_text ('My super long title', 10);
(I have not tested this, but it should work just fine.)
Charles Zink
source share