relevanssi_get_attachment_url

apply_filters( 'relevanssi_get_attachment_url', string $url, int $post_id )

Filters the attachment URL Relevanssi uses when reading attachment content. If you want to read content from attachments that are stored outside Media Library, you need to modify this value.

Parameters

$url
(string) The attachment URL, defaults to wp_get_attachment_url( $post_id ).

$post_id
(int) The attachment post ID.

More information

When reading attachment contents, Relevanssi uses by default the wp_get_attachment_url() function to get the attachment URL. If you keep your attachments in the Media Library, this is fine, but if you’re not using Media Library, this function will not return the correct value.

In that case, you need to use this filter hook to provide an alternate method of getting the URL. The exact method depends on what you’re trying to implement, but this filter hook expects you to provide an absolute URL to the attachment specified by the post ID.

You also need to modify relevanssi_get_attachment_posts_query and may need to modify relevanssi_get_attached_file. For a complete example (that doesn’t use this filter hook), see Making Relevanssi index WP Download Manager files.