Make WordPress Core

Opened 11 years ago

Closed 7 years ago

Last modified 7 years ago

#4679 closed enhancement (worksforme)

the_content() vs. the_excerpt() - apply different filters to posts without excerpt text specified

Reported by: fuggi Owned by: fuggi
Milestone: Priority: normal
Severity: normal Version: 2.2.1
Component: Formatting Keywords:
Focuses: Cc:


There is a problem with the way that WP handles the excerpt for posts, that do not have a excerpt text specified.

In this case WP applies the wp_trim_excerpt function via default filter which takes the posts content (get_the_content), applies the_content filters and then removes HTML etc.

So this means, that those excerpts will always have the filters for the_content applied and there is now way to prevent it from doing that to have different filters for the_content and the_excerpt (except from writing an excerpt of course).

It would make more sense if WP would not apply the filters for the_content in this case, so that plugin developers have the possibility to apply an other filter to the posts when displayed in the excerpt than when displayed as post. Plugin designers who want to add their action to both content and excerpt (if no own excerpt is written) should have the possibility to add a filter to get_the_content instead.

My plugin WP-Simpleviewer adds a Flash based gallery posts - and when these posts are viewed with the_excerpt() they show up with some javascript/html looking content, however I would like to show something like "Read the whole post to see the gallery".

So IMHO what has to be done is to add the possibility to add filters to get_the_content (according to the codex this does not work yet) and to remove the commented line from function wp_trim_excerpt(formatting.php):

$text = get_the_content('');
//$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);

Attachments (1)

post_template__formatting.diff (973 bytes) - added by fuggi 10 years ago.
Two files are changed: formatting.php and post_template.php

Download all attachments as: .zip

Change History (9)

#1 @foolswisdom
11 years ago

  • Milestone set to 2.4 (future)
  • Version set to 2.2.1

10 years ago

Two files are changed: formatting.php and post_template.php

#2 @fuggi
10 years ago

  • Owner changed from anonymous to fuggi
  • Status changed from new to assigned

#3 @fuggi
10 years ago

  • Keywords has-patch added; filters the_content the_excerpt removed

#4 @ffemtcj
10 years ago

  • Milestone changed from 2.5 to 2.6

#5 @Denis-de-Bernardy
9 years ago

I might be wrong, but isn't that call there on purpose? As in to strip shortcodes and similar stuff that should get discarded?

#6 @Denis-de-Bernardy
9 years ago

  • Component changed from Administration to Formatting
  • Keywords needs-patch added; has-patch removed
  • Milestone changed from 2.9 to Future Release

#7 @solarissmoke
7 years ago

  • Keywords needs-patch removed
  • Resolution set to worksforme
  • Status changed from accepted to closed

Since this ticket was created, a wp_trim_excerpt filter was added [10981], which allows plugin authors to completely override the default excerpt generation. I think this resolves the reporters' issue, which was that there was no way to modify generated excerpts.

#8 @dd32
7 years ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.