WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#9558 closed enhancement (fixed)

wp_trim_excerpt() is not filterable

Reported by: coffee2code Owned by:
Milestone: 2.8 Priority: low
Severity: minor Version: 2.7.1
Component: Template Keywords: has-patch
Focuses: Cc:

Description

the_excerpt(), used by most themes to obtain the excerpt for a post, calls get_the_excerpt() which in turn calls wp_trim_excerpt(). wp_trim_excerpt() will fabricate an excerpt for a post if one wasn't explicitly defined (and in doing so makes a number of assumptions about how to generate the except (i.e. stripping shortcodes and tags, grabbing so many words, and appending a non-filterable ellipsis of sorts (perhaps that bit is a separate ticket itself)).

Anyhow, the primary need in filtering wp_trim_excerpt() rather than fiddling with the excerpt via filters for get_the_excerpt() or the_excerpt() is that with the latter two it is not clear whether the excerpt is real or fabricated.

The attached patch simply adds a filter on the return value of wp_trim_excerpt(). It sends along the potentially-generated excerpt as well as the original (raw) excerpt that was passed in, allowing plugins to identify a fabricated excerpt and react accordingly.

Attachments (1)

bug9558-make-wp_trim_excerpt-filterable.diff (526 bytes) - added by coffee2code 6 years ago.
Aforementioned patch

Download all attachments as: .zip

Change History (2)

@coffee2code6 years ago

Aforementioned patch

comment:1 @ryan6 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [10981]) Add wp_trim_excerpt filter. Props coffee2code. fixes #9558

Note: See TracTickets for help on using tickets.