(.*?)<\/figcaption>/is', $original_figure, $caption_match)) {
+ $caption = $caption_match[1]; // только содержимое
+ }
+
+ // Генерируем HTML изображения
+ $replacement = render_webp_picture_by_post($post->ID);
+
+ // Добавляем подпись, если есть
+ if (!empty($caption)) {
+ $replacement .= '' . esc_html($caption) . '
';
+ }
+
+ // Заменяем первое вхождение ... на $replacement
+ $content = preg_replace('/.*?<\/figure>/is', $replacement, $content, 1);
+ }
+
+ return $content;
+}
+