Make WordPress Core

Opened 16 years ago

Last modified 2 weeks ago

#12084 new enhancement

allow preserving HTML in the_excerpt (specify allowed tags for strip_tags in wp_trim_excerpt)

Reported by: sillybean's profile sillybean Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Formatting Keywords: has-patch
Focuses: Cc:

Description

Right now, wp_trim_excerpt is destructive. You can filter it, but once tags are stripped, you can't get them back without recreating the excerpt from the raw input. It would be nice if theme developers had an option to preserve at least some of the HTML formatting when using excerpts as post teasers (see #9260).

Attachments (2)

excerpt_tags.diff (624 bytes) - added by sillybean 16 years ago.
Creates excerpt_tags filter for wp_trim_content
excerpt_tags2.diff (1.0 KB) - added by sillybean 16 years ago.
balances tags after truncating excerpt

Download all attachments as: .zip

Change History (10)

@sillybean
16 years ago

Creates excerpt_tags filter for wp_trim_content

#1 @sillybean
16 years ago

  • Summary changed from allow preserving HTML in the_excerpt (make strip_tags optional in wp_trim_excerpt) to allow preserving HTML in the_excerpt (specify allowed tags for strip_tags in wp_trim_excerpt)

@sillybean
16 years ago

balances tags after truncating excerpt

#2 @sillybean
16 years ago

Second patch balances the tags after the excerpt has been truncated, which makes more sense. However, it can result in weirdness with the word count. Not sure how to get around that without some really painful regex.

This patch also preserves shortcodes in excerpts, which seems logical if we're allowing HTML.

#3 @nacin
16 years ago

  • Milestone changed from Unassigned to Future Release

#4 @ocean90
14 years ago

  • Keywords changed from has-patch, needs-testing to has-patch needs-testing

Duplicate: #21558

#5 @chriscct7
11 years ago

  • Keywords needs-refresh added
  • Severity changed from minor to normal

#6 @SirLouen
3 months ago

  • Keywords needs-testing removed

Added needs-refresh by @chriscct7, so needs-testing should also be removed.

#7 @abcd95
3 weeks ago

I think we should have a single excerpt_allowed_tags filter inside wp_trim_excerpt(), defaulting to '' (strip everything — identical to current behaviour). When non-empty, bypass wp_trim_words(), strip only disallowed tags, find the word-boundary cut point on a plain-text copy, then run force_balance_tags() before appending the more string.

I am working on this fix and testing some changes; the PR should be up shortly.

This ticket was mentioned in PR #11438 on WordPress/wordpress-develop by @abcd95.


2 weeks ago
#8

  • Keywords needs-refresh removed
Note: See TracTickets for help on using tickets.