how to get specific part of shortcode?

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:

Read More
<a href="#"><img src="image.jpg" alt="" title="my title" width="435" height="363" class="size-full wp-image-52788" /></a>
my caption

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?

Related posts

1 comment

  1. I found an answer

    This part

    $output2 = preg_match_all('/caption="(.*?)"/', $post->post_content, $matches2);
    

    replace with the

    $output2 = preg_match_all('//>(.*?)[/caption]/u', $post->post_content, $matches2);
    

Comments are closed.