Support Forum

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Custom Fields Reply To: Custom Fields

#12870
Tom
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.