Support » Plugins » Hacks » wp_trim_words formatting

  • Resolved dannybeton

    (@dannybeton)


    I’m using the wp_trim_words function to just take the snippet of a custom post’s content:

    echo ‘<p>’ . wp_trim_words( get_the_content(), 50 ) . ‘</p>’;

    The content text is formatted as follows:

    “One of our VIP members (well… Ned) has his 1984 black Porsche 924 for sale!

    This car is in truly terrific order and is well known locally having been frequently shown at numerous classic car events. To see the advert on DoneDeal click here.”

    But when wp_trim_words() is used it’s displayed as:

    “One of our VIP members (well… Ned) has his 1984 black Porsche 924 for sale! This car is in truly terrific order and is well known locally having been frequently shown at numerous classic car events. To see the advert on DoneDeal click here.”

    The break return after “for sale!” is gone.. Is there any way to keep the formatting of the post when using wp_trim_words() ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Timothy Jacobs

    (@timothyblynjacobs)

    Nope, WordPress calls wp_strip_all_tags() in that function, there is no simple way around that because otherwise your html would be counted as words. The only alternative would be to write or find your own that ignores any html tags.

    Ok, thanks for the response Timothy! 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_trim_words formatting’ is closed to new replies.