apply_filters( 'get_the_excerpt', string $post_excerpt , WP_Post $post )
Filters the retrieved post excerpt.
Description Description
Parameters Parameters
- $post_excerpt
-
(string) The post excerpt.
- $post
-
(WP_Post) Post object.
Source Source
Changelog Changelog
Version | Description |
---|---|
4.5.0 | Introduced the $post parameter. |
1.2.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
When using this filter on a string stored in a variable, the string will not be trimmed by the
excerpt_length
filter.This is expected behaviour. By passing a long string through the
get_the_excerpt
filter, you are simulating the case where you have entered the same long text into theExcerpt
field in theEdit Post
screen. When a custom excerpt is present on the post, no trimming is done (though other content filters are applied).If you want to simulate the automatic excerpt trimming on arbitrary text, you can pass the text to
wp_trim_words()
yourself, with a function like this:Expand full source codeCollapse full source code
The function above can be used like this: