Home › Forums › Pro Support › Custom Fields › Reply To: Custom Fields
January 23, 2020 at 6:03 pm
#12870
Keymaster
You could try this function:
function gwen_limit_text( $text, $limit ) {
if ( str_word_count( $text, 0 ) > $limit ) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$limit]) . '...';
}
return $text;
}
Then, in your hook, do this:
gwen_limit_text( $your_custom_field, 50 );
50
being the word limit.