WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 18 months ago

#33468 reviewing enhancement

Add image caption hook

Reported by: guillaumemolter Owned by: SergeyBiryukov
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Media Keywords: needs-patch
Focuses: template Cc:
PR Number:

Description

There is currently no proper way to hook into image captions.

Image captions are stored into the excerpt of attachments posts but when the caption is retrieved it doesn't go threw any specific filter.

I think it would be nice to have a add_filter ( 'image_caption', 'your_filter' ); or something similar.

This was already discussed here : https://wordpress.org/ideas/topic/add-image-caption-hook#post-28710

Captions are used by multiple themes and plugins. They are fully supported and showed in twenty-fifteen so I think we should be able to properly hook/filter them.

Change History (7)

#1 follow-ups: @DrewAPicture
4 years ago

Something to consider is that captions are both output in the editor and on the front-end. When HTML support was added to captions a few (maybe more than a few, I don't remember) versions ago, it kind of introduced a new dynamic in terms of what would be considered valid not to break the editor and/or gallery shortcodes on display.

I would thing that any kind of filter added to the caption output would have to keep both front-end and editor use-cases in mind.

@guillaumemolter: Would you like to try your hand at Submitting a patch?

#2 in reply to: ↑ 1 @guillaumemolter
4 years ago

Replying to DrewAPicture:

@guillaumemolter: Would you like to try your hand at Submitting a patch?

I most certainly will! Contributing to Core has been on my bucket list for quite a while now so this might be the perfect occasion!

Last edited 4 years ago by guillaumemolter (previous) (diff)

#3 in reply to: ↑ 1 ; follow-up: @guillaumemolter
4 years ago

Replying to DrewAPicture:

Something to consider is that captions are both output in the editor and on the front-end. When HTML support was added to captions a few (maybe more than a few, I don't remember) versions ago, it kind of introduced a new dynamic in terms of what would be considered valid not to break the editor and/or gallery shortcodes on display.

I would thing that any kind of filter added to the caption output would have to keep both front-end and editor use-cases in mind.

Thank you for the feedback I'll make sure to take this into consideration. I'll study how Core is currently handling Captions as well as how other filters work. Can you think of a similar filter that I can use as a reference?

#4 in reply to: ↑ 3 @DrewAPicture
4 years ago

  • Keywords needs-patch added

Replying to guillaumemolter:

Thank you for the feedback I'll make sure to take this into consideration. I'll study how Core is currently handling Captions as well as how other filters work. Can you think of a similar filter that I can use as a reference?

Not off the top of my head, unfortunately.

#5 @wonderboymusic
4 years ago

  • Milestone changed from Awaiting Review to Future Release

@guillaumemolter: check out 'wp_video_shortcode' filter.

#6 @xma
19 months ago

Hi to all, actualy there is a img_caption_shortcode, trought that we can change all attribute passed to caption or wp-caption shortcode, also caption attribute that define caption text.

#7 @SergeyBiryukov
18 months ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing
Note: See TracTickets for help on using tickets.