Hi,
in some cases when search word was at the beginning of the post picture caption was still being displayed. Adding this line to function solved problem:
$content = preg_replace(“/\[caption .+?\[\/caption\]/”, “”, $content);
source of this line of code: https://www.ads-software.com/support/topic/how-to-remeove-first-image-from-the_content
thanks to member talkstory
so function looks like this:
add_filter('relevanssi_pre_excerpt_content', 'remove_captions');
function remove_captions($content) {
#error_reporting(E_ALL);
$content = preg_replace("/<\/a>.*?\[/", "</a>[", $content);
$content = preg_replace("/<dd>(.*)<\/dd>/", "", $content);
$content = preg_replace("/<figcaption>(.*)<\/figcaption>/", "", $content);
$content = preg_replace("/\[caption .+?\[\/caption\]/", "", $content);
return $content;
}