WordPress.org

Ready to get started?Download WordPress

Codex

Plugin API/Filter Reference/get the excerpt

Contents

Description

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_filter() function.

Usage

When the 'get_the_excerpt' filter is called, it 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.

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

Examples

Custom "More" Link

This example from the twentyeleven theme appends a custom "Read more" link to post excerpts. See has_excerpt() and is_attachment()

/**
 * Adds a pretty "Continue Reading" link to custom post excerpts.
 *
 * To override this link in a child theme, remove the filter and add your own
 * function tied to the get_the_excerpt filter hook.
 */
function twentyeleven_custom_excerpt_more( $output ) {
  if ( has_excerpt() && ! is_attachment() ) {
    $output .= twentyeleven_continue_reading_link();
  }
  return $output;
}
add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );

See Also