relevanssi_excerpt_part

apply_filters( 'relevanssi_excerpt_part', string $excerpt_text, array $excerpt, int $post_id )

Filters the individual excerpt parts (one or many, depending on settings) after highlighting, ellipsis and the <span> tags have been added.

Parameters

$excerpt_text
(string) The excerpt part text, wrapped in <span class="excerpt_part"> tags.

$excerpt
(array) The whole excerpt part array. text has the excerpt text, start is a Boolean flag that is true if the excerpt is from the beginning of the post, source is the part of the post where the excerpt is from and hits is the number of search term matches in the part.

$post_id
(int) The post ID.

More information

When Relevanssi creates excerpts, the process happens in relevanssi_do_excerpt(). Terms are processed, shortcodes are managed, the_content filters are applied, tags are stripped and finally the excerpt is created.

The excerpt is then passed through the relevanssi_excerpt hook. After that the search term highlighting is added, an ellipsis is added and finally the excerpt is passed through this hook and then returned.

This hook is a good place to attach to if you want to make changes to the excerpt. For example, if you are creating excerpts from many different parts of the post (like post content and comments), you can add the excerpt source to excerpt with this function:

add_filter( 'relevanssi_excerpt_part', 'rlv_excerpt_part_source', 10, 2 );
/**
 * Adds the excerpt part source.
 *
 * @param string $excerpt_text The excerpt text, not used.
 * @param array  $excerpt      The full excerpt array.
 *
 * @return string The modified excerpt.
 */
function rlv_excerpt_part_source( string $excerpt_text, array $excerpt ) : string {
    return '<span class="excerpt_part"><span class="excerpt_source">'
        . $excerpt['source']
        . '</span>'
        . $excerpt['text']
        . '</span>';
}