I have a script, that catches all images from posts based on shortcodes with captions and outputs images and captions to carousel
this is how looks shortcode:
and this is php code that extract captions and iamges
$output = preg_match_all('/<img.+src=['"]([^'"]+)['"].*>/i', $post->post_content, $matches);
$output2 = preg_match_all('/caption="(.*?)"/', $post->post_content, $matches2);
$gallery = $matches[1];
$captions = $matches2[1];
$count_of_captions = 0;
foreach ($captions as $capt) {
$js .= 'captions[' . $ii . '] = "' . $capt . '";' . "n";
$ii++;
if ($capt != "") {
$count_of_captions++;
}
}
all of that have worked on old wordpress version. now wordpress outputs caption in this method:
<img class="size-full wp-image-52725" src="image.jpg" alt="" height="347" /> my caption
now captions is after image tag. how can I extract captions now?
I found an answer
This part
replace with the