Caption filter requires manual re-save... sometimes

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.

Hello @deciplex,

Thanks for writing to us.

I would suggest you go to the WordPress dashboard → Cornerstone → Settings → Clear Cache. After that, also clear any page cache, CDN cache, and object cache so the rebuilt markup is actually served on the frontend.


Hope it helps
Thanks

Hello,

I tried that but it didn’t do anything. I understood afterwards that it concerned my old articles, probably those created BEFORE the filter was added in 2023 in Themeco… What worked was to re-trigger the save of each post…

Hey @deciplex,

Your code would need modification. Regretfully, we do not provide custom code support or suggestions as part of our regular theme support. We can only do that in our One service.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.