get_the_excerpt WordPress Filter Hook

The get_the_excerpt hook is used to retrieve the excerpt of a post. This hook is generally used in conjunction with the_excerpt() function, which echo’s the excerpt.

apply_filters( 'get_the_excerpt', string $post_excerpt, WP_Post $post ) #

Filters the retrieved post excerpt.


Parameters

$post_excerpt

(string)The post excerpt.

$post

(WP_Post)Post object.


Top ↑

More Information

The get_the_excerpt filter is used to filter the excerpt of the post after it is retrieved from the database and before it is returned from the get_the_excerpt() function.

When the get_the_excerpt filter is called, the filter function is passed a single argument containing the post excerpt.

function filter_function_name( $excerpt ) {
  # ...
}
add_filter( 'get_the_excerpt', 'filter_function_name' );

Where ‘filter_function_name‘ is the function WordPress should call when the excerpt is being retrieved. Note that the filter function must return the excerpt after it is finished processing, or page sections showing an excerpt will be blank, and other plugins also filtering the excerpt may generate errors.

The ‘filter_function_name‘ should be a unique function name. It cannot match any other function name already declared.


Top ↑

Source

File: wp-includes/post-template.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
4.5.0Introduced the $post parameter.
1.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.