There are various ways to achieve this as listed following.
Using wordwrap() function :
function shortened_description($cutlength) {
$content = get_field('event_short_description');
$charcount = strlen($content);
$content = wordwrap($content, 28);
$content = explode("\n", $content);
$shorter = $content[0];
if ($charcount >= $cutlength) {
echo $shorter . '... <a href="' . get_permalink() . '">more ></a>';
} //$charcount >= $cutlength
else {
echo $shorter;
}
}
Using preg_match() function :
function shortened_description($cutlength) {
$content = get_field('event_short_description');
$charcount = strlen($content);
if ($charcount >= $cutlength) {
preg_match("/^.{1,$cutlength}\b/s", $content, $match);
echo $match[0] . '... <a href="' . get_permalink() . '">more ></a>';
} //$charcount >= $cutlength
else {
echo $content;
}
}
Using wp_trim_words() function :
( Note it will trim strings based on number of words passed as a parameter )
function shortened_description($cutlength) {
$content = get_field('event_short_description');
$shorter = wp_trim_words($content, $cutlength, '... <a href="' . get_permalink() . '">more ></a>');
echo $shorter;
}