Formatting: Add excerpt_allowed_tags filter to preserve HTML tags in wp_trim_excerpt()#11438
Formatting: Add excerpt_allowed_tags filter to preserve HTML tags in wp_trim_excerpt()#11438himanshupathak95 wants to merge 7 commits intoWordPress:trunkfrom
Conversation
640b788 to
309c7e8
Compare
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
309c7e8 to
8272924
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
…ter-based trimming
8272924 to
089bb7c
Compare
Trac ticket: https://core.trac.wordpress.org/ticket/12084
wp_trim_excerpt()has always stripped all HTML from auto-generated excerpts unconditionally, viawp_trim_words()→wp_strip_all_tags(). There was no hook to preserve any markup, making it impossible for themes and plugins to retain semantic HTML (e.g.,<strong>,<em>,<a>) in excerpts without replacing the entirewp_trim_excerptfunction.This PR introduces a new
excerpt_allowed_tagsfilter inwp_trim_excerpt()that defaults to an empty string (fully backward compat). When a non-empty allowed-tags string is supplied, a new HTML-aware trimming path istaken instead of the
wp_trim_words()path.Usage
Testing
You can run and check the tests using -