WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_trim_words formatting (3 posts)

  1. dannybeton
    Member
    Posted 8 months ago #

    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() ?

  2. Timothy Jacobs
    Member
    Posted 8 months ago #

    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.

  3. dannybeton
    Member
    Posted 7 months ago #

    Ok, thanks for the response Timothy! :)

Reply

You must log in to post.

About this Topic