19 Responses

  1. Ryan Imel

    Nice catch, I haven’t used that one yet.

  2. Bill Robbins

    What a great solution. Thanks for sharing your discovery Brian.

  3. Bill Robbins

    If you keep using $krogsquery, I wonder how long it will be before it ends up in a distributed theme someplace.

  4. Ryan Hellyer

    Awesome tip. Thanks Brian!

    I usually end up rolling some half-baked custom function to do that. Nice to see there’s something built into core for it now.

  5. Clark

    Score. Any idea if it preserves HTML?

  6. Use wp_trim_words to limit words in WordPress | Jake Spurlock

    [...] Use wp_trim_words to limit words in WordPress. Share this:FacebookTwitterStumbleUpon This entry was posted in WordPress and tagged function, [...]

  7. David Chandra

    oh no….
    now i have to update all my theme..

    thanks alot brian…

    you are awesome!

  8. Farid

    My friend u don’t know who easy you make it….maaaaaaaaN. …..I was really searching for this solution from recent two months… NOw i can use it simply and easyle……Thanks bro………….thanks

  9. Andrew

    Hello there. Love this tip. Please can you help with any way to retain the formatting of the text that is called? It seems that it has to wipe out all formatting which is a pain :(

    Any help greatly appreciated!

  10. Andrew

    Hi, any advice on that?

    I am currently pulling in custom fields as follows:

    echo wp_trim_words( get_field(‘field_name’), 1000, ‘ ‘ );

    and wrapping in wp_trim_words. It works fine except that there is no formatting…which is no good.

    Hope you can offer some advice.

    Many thanks. AB

  11. Rob J

    Nice tip!. Would anyone know if it is possible to trim the text once the first full stop is reached…rather than just a random word after a particular number of words reached?

Leave a Reply