Opened 13 years ago
Closed 9 years ago
#18037 closed enhancement (maybelater)
inconsistency in filters for the_content and the_excerpt
Reported by: | opajaap | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.2 |
Component: | Posts, Post Types | Keywords: | needs-patch |
Focuses: | Cc: |
Description
My plugin replaces a keytext by a div tag using a filter:
add_filter('the_content', 'my_proc');
This filter appears also to be run in an excerpt, while my div is stripped in the excerpt.
When my div is stripped i want - instead of that div - to print a notification like - Here belongs my div -.
So, either i need a boolean variable or function that tells me that my filter is currently run by a call to the_excerpt(), OR the filter should not be run on the excerpt if it is not added to the excerpts filter list.
I tried a workaround by adding a new filter to the_excerpt and setting my own global to indicate i am in an excerpt, but unfortunately this filter is run after the the_content filter, despite fiddling with filter priorities. So, in a list (archive) the first excerpt is still in error.
The documentation says about filters:
the_content
applied to the post content retrieved from the database, prior to printing on the screen (also used in some other operations, such as trackbacks).
and
the_excerpt
applied to the post excerpt (or post content, if there is no excerpt) retrieved from the database, prior to printing on the screen (also used in some other operations, such as trackbacks).
It appears that not only the_excerpt filters are run on the content if there is no excerpt, what is fine, but it works also the other way around: the the_content filters are run on the excerpt. This is an inconsistency, and basically my problem.
Change History (4)
#2
@
12 years ago
Agreed the filters on these functions (and their get_* brothers) are a complete mess and we really need to be more consistent. The difficult is, as always backwards compatibility.
Your problem occurs because if there is no explicit excerpt created by the user, WP takes the first bit of text from the full post content instead, applying the filters declared on function the_content(). See function wp_trim_excerpt() in wp-includes/formatting.php which is called as a filter on get_the_excerpt().
There are many similar tickets, some such as #4679 going back a long way!
#4
@
9 years ago
- Keywords needs-patch added
- Milestone Awaiting Review deleted
- Resolution set to maybelater
- Status changed from new to closed
Closing as maybelater. Complete lack of interest on the feature on the ticket over the last 3 years. Feel free to reopen when more interest re-emerges (particularly if there's a patch).
BTW looking at is_archive() or is_search() is not a solution. Many theme(modification)s use the_content() instead of the_excerpt() in which case i would draw the wrong conclusion.