benecaster_search_result_excerpt
Filters the excerpt string for each search result after matched terms have been wrapped in `mark` tags for highlight display. Use to modify the highlighted excerpt — for example, to change the highlight wrapper element, append episode metadata, or strip HTML for plain-text contexts.
This is a Free filter. It fires per result, before the full result set is assembled by [benecaster_search_results](/hooks/benecaster_search_results/).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$excerpt |
string |
— | Excerpt with matched terms wrapped in `mark` |
$episode_id |
int |
— | Episode post ID |
$query |
string |
— | Search term |
Returns:
string
Examples
Replace mark with custom highlight span
add_filter( 'benecaster_search_result_excerpt', function( string $excerpt, int $episode_id, string $query ): string {
return str_replace(
[ '<mark>', '</mark>' ],
[ '<span class="highlight">', '</span>' ],
$excerpt
);
}, 10, 3 );
Append episode number to excerpt
add_filter( 'benecaster_search_result_excerpt', function( string $excerpt, int $episode_id, string $query ): string {
$ep_number = get_post_meta( $episode_id, '_benecaster_episode_number', true );
if ( $ep_number ) {
$excerpt .= ' <small>Episode ' . esc_html( $ep_number ) . '</small>';
}
return $excerpt;
}, 10, 3 );
Affects
- GET /benecaster/v1/search REST endpoint