Make WordPress Core

Opened 11 years ago

Last modified 2 months ago

#34396 new enhancement

Gallery shortcode : make image captions relative to the current gallery

Reported by: Fab1en Owned by:
Priority: normal Milestone:
Component: Gallery Version: 3.5
Severity: normal Keywords:
Cc: Focuses: administration

Description

In the media frame, the "Caption" field is used to set a caption for images. But this field has several other effects that are not always intended by the website author.

  • Changes to this field are saved on the database (in the excerpt field of the attachment post) as soon as the field is unfocused : no preview is possible, changes are put online directly. Changes are still applied even if "Update" button is not clicked.
  • For single image insertion, caption is saved in the post content, inside the [caption] shortcode. But for multiple images, caption is saved globally, not inside the [gallery] shortcode.
  • When modifying a gallery, changing the caption field right under the image also updates the caption field on the right panel, and saves it globally when the focus is moved. So even when the "Update gallery" button is not clicked, the changes are still saved in the database, but they are not reflected in the editor until the page is reloaded.
  • When an image is use in several galleries, updating the caption associated with this image in one gallery also updates the caption on the other gallery. This is very different from the behavior of other fields displayed on the right panel (columns, link to, size) that change only the current gallery.
  • Modifying the caption field is the attachment details edition view or in the media library grid view will change the caption used for this image in a gallery.

Change History (2)

#1 @Fab1en
11 years ago

I see two directions to make this happen :

  1. Store the caption of images is the gallery directly in the gallery shortcode. That is not possible today (because HTML is not allowed in shortcode attributes) but it could be possible with the future shortcode format that will allow to split shortcode content into several parts, each part being an image caption.
  2. Store the caption in a postmeta field, linking it to the gallery id. This is easier to achieve but will not solve the previewing issue.

#2 @dfuchs72
2 months ago

I'd like to resurrect this proposal because the problem is really annoying when you want to re-use images on your website. You just can't have the same image in different galleries with different captions, the caption is global.

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.

I can see basically the same two solutions as @Fab1en :

  1. 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’.

  1. 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.

On the other hand, I don't know if anyone is willing to put in work to improve classic editing. I'd be very grateful, though, and this is not something I can easily achieve with some PHP code of my own.

Note: See TracTickets for help on using tickets.