the_excerpt
Filters the content of the post's “Excerpt” field before it is displayed. Used in the_excerpt().
Read the the_excerpt() and get_the_excerpt() function descriptions to learn about other ways to modify a post excerpt.
Usage
add_filter( 'the_excerpt', 'wp_kama_the_excerpt_filter' );
/**
* Function for `the_excerpt` filter-hook.
*
* @param string $post_excerpt The post excerpt.
*
* @return string
*/
function wp_kama_the_excerpt_filter( $post_excerpt ){
// filter...
return $post_excerpt;
}
- $post_excerpt(string)
- The content of the “Excerpt” field.
Examples
#1 Wrap the excerpt content in a custom block
add_action( 'the_excerpt', 'modify_the_excerpt' );
function modify_the_excerpt( $post_excerpt ) {
return '<div class="custom-block">' . $post_excerpt . '</div>';
}Changelog
| Since 0.71 | Introduced. |
Where the hook is called
the_excerpt
the_excerpt
the_excerpt
the_excerpt
wp-includes/post-template.php 401
echo apply_filters( 'the_excerpt', get_the_excerpt() );
wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php 981
$excerpt = apply_filters( 'the_excerpt', $excerpt );
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php 2034
$excerpt = apply_filters( 'the_excerpt', $excerpt );
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php 1447
$caption = apply_filters( 'the_excerpt', $caption );
wp-includes/comment.php 3376
$excerpt = apply_filters( 'the_excerpt', $post->post_excerpt );
Where the hook is used in WordPress
wp-includes/default-filters.php 212
add_filter( 'the_excerpt', 'wptexturize' );
wp-includes/default-filters.php 213
add_filter( 'the_excerpt', 'convert_smilies' );
wp-includes/default-filters.php 214
add_filter( 'the_excerpt', 'convert_chars' );
wp-includes/default-filters.php 215
add_filter( 'the_excerpt', 'wpautop' );
wp-includes/default-filters.php 216
add_filter( 'the_excerpt', 'shortcode_unautop' );
wp-includes/default-filters.php 217
add_filter( 'the_excerpt', 'wp_replace_insecure_home_url' );
wp-includes/default-filters.php 218
add_filter( 'the_excerpt', 'wp_filter_content_tags', 12 );