WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#7100 closed defect (bug) (fixed)

don't parse shortcodes in excerpts

Reported by: hailin Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

some themes display excerpts by calling the_excerpt(), which calls get_the_excerpt, then if there is no original excerpt, call apply_filters('get_the_excerpt', $output). Eventually wp_trim_excerpt() is called, and apply_filters('the_content', $text). The issue is that the_content filter parses shortcode such as [video ..] or [audio ..], and the result is truncated to 55 words, producing ugly output

<eagleclaw2> I am proposing not to parse, nor to display, shortcode in wp_trim_excerpt. But then we need to enumerate and skip every type of shortcode ... not pretty..

<rboren> eagleclaw2: Temporarily remove shortcode from the_content filter for wp_trim_excerpt()?
<rboren> That would leave use with raw shortcodes.

<rboren> But, we might need to write strip_shortcodes() at some point.
<eagleclaw2> you mean to strip all the shortcodes, given a raw post ?
<rboren> Something analogous to strip_tags() to be used in similar situations.
<rboren> Just wondering out loud. :-)
<eagleclaw2> agreed. let me attemp to write strip_shortcodes()

Attachments (1)

7100_strip_shortcodes.diff (1.3 KB) - added by hailin 7 years ago.
updated patch using shortcode_tags

Download all attachments as: .zip

Change History (6)

comment:1 @DD327 years ago

  • Milestone 2.7 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

While this ticket is mainly [gallery] it applies to all shortcodes.

#6380

comment:2 @DD327 years ago

Hm.. Actually.. I'm not sure i should've closed this so fast.

The other has mainly gone in the direction of an alternate idea of trimming first and then parsing the shortcodes..

comment:3 @hailin7 years ago

DD32:

I've tried to enumerated all shortcodes here and remove them from raw post content.

The function now is useful in producing excerpts, it may be useful in other contexts as well...

comment:4 @hailin7 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

@hailin7 years ago

updated patch using shortcode_tags

comment:5 @ryan7 years ago

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

(In [8054]) Strip shortcodes when making excerpts. Props hailin. fixes #7100

Note: See TracTickets for help on using tickets.