0

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.

2
  • So your goal is to limit the number of characters in the_excerpt()?
    – mor7ifer
    Commented Mar 5, 2012 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
    Commented Mar 5, 2012 at 17:21

1 Answer 1

1

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)

1
  • Fantastic. Thank you! This is what I was looking for.
    – willbeeler
    Commented Mar 5, 2012 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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