• I’m working with classic themes and the [gallery] shortcode, and I would like to re-use images for galleries in different posts, and they should get different captions in each post.

    As far as I’ve figured out, captions work like this:

    When you upload an image and give it a caption, it is stored in the post_excerpt field of the attachment record in the ‘posts’ table. At the same time, for single images, the caption is embedded in the [caption] shortcode, so it becomes part of the post content and can be edited without affecting the caption stored in the attachment record, so you can have the same image with different captions in different posts.

    For galleries, there seems to be no such mechanism. When I alter an image caption in a gallery, the change is written back to the image’s attachment record and will affect galleries in other posts because they all draw their captions from the attachment record.

    This consistency is fine for titles and alt texts, but a caption is a comment on an image, not a description of its contents, so it’s context-specific. For instance, a picture of an eagle could be captioned ‘Haliaeetus leucocephalus’ in a post about bird species and ‘What we saw in the sky’ in a post about a field trip on the same website. I hope I’ve made the problem clear.

    With my moderate knowledge of WordPress, I can imagine two solutions:

    – Add information about post-specific gallery image captions to the ‘postmeta’ table. Probably rather inefficient, and I can’t think of a format to reference them. The block editor and page builders would have to adapt to make use of this.

    – Extend the [gallery] shortcode to include caption information, e.g like this:
    [gallery ids="32,65,128" captions="Our field trip||What we saw in the sky"]

    The empty string between the middle separators would mean ‘no caption specified, take it from the attachment record’.

    Of course, this would work only for the shortcode, but I’d be happy with that.

    • This topic was modified 3 weeks, 5 days ago by Daniel Fuchs. Reason: typo
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.