Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm already familiar with the_excerpt() and get_the_excerpt() functions. These two functions relate specifically to some node/taxonomy/whatever (post, page, custom post type) inside of Wordpress, unless I'm mistaken.

What if I have some external text, and wanted to pass it through a concatenation function. Does anyone know the function to do that?

What I'm trying to avoid, is creating a new function or re-writing an old function to limit words inside of a string. For example,

echo some_excerpt_function($text, $amount_of_words_to_limit);

I'm assuming Wordpress has something similar to this, that's why I'm asking.

share|improve this question
    
So your goal is to limit the number of characters in the_excerpt()? –  m0r7if3r Mar 5 '12 at 14:11
    
Hi. Not really. The goal was to do a basic excerpt but use the internal Wordpress function, instead of writing my own and adding it to the functions.php file. –  willbeeler Mar 5 '12 at 17:21

1 Answer 1

up vote 1 down vote accepted

Use wp_trim_words( $text, $num_words, $more_text )

The first argument is the text to trim, the second is the number of words you want and the third is the truncation text which defaults to an ellipsis.

The function is located in wp-includes/formatting.php line 1920 (v3.3.1)

share|improve this answer
    
Fantastic. Thank you! This is what I was looking for. –  willbeeler Mar 5 '12 at 15:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.