Hi,
I added a filter to automatically inject image captions as a data attribute on the front end. The filter works correctly, but I noticed that on older articles, the page needs to be re-saved from Cornerstone for the filter to take effect. Is there a better way to handle this?
We have a large number of articles (in French and English) and re-saving them all manually would be very time-consuming. I already tried clearing the Cornerstone cache but it did not change anything.
Here is the filter I added:
add_filter('cs_apply_image_atts', function($atts) { if (!empty($atts['src'])) { $id = attachment_url_to_postid($atts['src']); if ($id) { $caption = wp_get_attachment_caption($id); if ($caption) $atts['data-caption'] = esc_attr($caption); } } return $atts;});
Thank you for your help.