Make WordPress Core

Opened 9 years ago

Last modified 5 years ago

#33468 reviewing enhancement

Add image caption hook

Reported by: guillaumemolter's profile guillaumemolter Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Media Keywords: 2nd-opinion
Focuses: template Cc:

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 (8)

#1 follow-ups: @DrewAPicture
9 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
9 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 9 years ago by guillaumemolter (previous) (diff)

#3 in reply to: ↑ 1 ; follow-up: @guillaumemolter
9 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
9 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
9 years ago

  • Milestone changed from Awaiting Review to Future Release

@guillaumemolter: check out 'wp_video_shortcode' filter.

#6 @xma
7 years 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
7 years ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#8 @Howdy_McGee
5 years ago

  • Keywords 2nd-opinion added; needs-patch removed

The wp_get_attachment_caption filter was added in WP v4.6.0 - is there anything else on this ticket that needs consideration?

Note: See TracTickets for help on using tickets.