I have a bit of a conundrum. I want to be able to generate PHP code that will automatically remove the [caption ...........] ...... [/caption] from the first image only without removing the image and leaving the caption of all other images in the content in place.
$content = $post->post_content;
$content = strip_shortcodes( $content );
$content = apply_filters('the_content', $content);
But that removes all images as well.
I substituted $content = strip_shortcodes( $content ); with:
$content = preg_replace("/\[caption.*\[\/caption\]/", '', $content);
but that doesn't work.
I need to save my content with the caption because I want it to appear on my mobile site. On my general website I don't want the caption to be displayed but for the first image only.
Any suggestions would be greatly appreciated.