apply_filters( 'relevanssi_related_output', string $related_output )
This filter hook filters the complete HTML output of the Related Posts element.
Parameters
$related_posts
(string) The HTML output for the Related Posts element.
More information
Relevanssi creates the Related Posts with the relevanssi_related_posts()
function. Relevanssi gets the post IDs with relevanssi_get_related_post_ids()
and then uses the related posts template file to convert the list of IDs to the actual HTML element with all the information about the posts.
Relevanssi returns the output through this filter, so if you want to change how the Related Posts appear, this filter hook gives you complete control over the output. If the Related Posts come from the cache, the cached output also passes through this filter as they usually do.
If you want to modify the selection of posts, you can use the relevanssi_related_args
to modify the WP_Query arguments for the query. If you’re going to make significant changes to how the posts appear, it’s generally better to modify the template used. Relevanssi caches whatever comes out of the template, which is better than making non-cached changes with this filter hook.