[wp-trac] [WordPress Trac] #29533: wp_trim_words preserves HTML tags

WordPress Trac noreply at wordpress.org
Wed Sep 24 18:41:35 UTC 2014


#29533: wp_trim_words preserves HTML tags
-------------------------------------+------------------------------
 Reporter:  Mekku                    |       Owner:
     Type:  enhancement              |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Formatting               |     Version:  trunk
 Severity:  normal                   |  Resolution:
 Keywords:  reporter-feedback close  |     Focuses:
-------------------------------------+------------------------------

Comment (by thudfactor):

 Hey, I managed to do something like this by stringing a few things
 together. You encode the tags, trim the string, decode the tags, then run
 WP's force_balance_tags (
 http://codex.wordpress.org/Function_Reference/force_balance_tags ) to make
 sure any tags closed on the wrong side of the trim are balanced.

 For example:

 {{{
 force_balance_tags(html_entity_decode(wp_trim_words(htmlentities($text))));
 }}}

 My real-life use case for this is outputting an "excerpt" of an ingested
 RSS feed in a template.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/29533#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list