#50801 closed enhancement (fixed)
A filter for wp_get_attachment_image() html output
Reported by: | prionkor | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.6 | Priority: | normal |
Severity: | normal | Version: | 5.4.2 |
Component: | Media | Keywords: | has-patch has-unit-tests commit has-dev-note |
Focuses: | Cc: |
Description
The function wp_get_attachment_image()
is used to output image tags in WP sites. Currently it has a filter for attr but not filter on html output of the function. I am proposing a filter so plugin developers can modify its output.
An example use case:
Output of <picture>
tag instead of <img>
for supporting multiple format of images (jpeg, webp).
<picture> <source type="image/jpeg" src="foo.jpg" /> <img src="foo.webp" alt="Bar" /> </picture>
Attachments (2)
Change History (27)
This ticket was mentioned in PR #440 on WordPress/wordpress-develop by prionkor.
4 years ago
#1
- Keywords has-patch added
This ticket was mentioned in Slack in #core by sisir. View the logs.
4 years ago
This ticket was mentioned in PR #447 on WordPress/wordpress-develop by donmhico.
4 years ago
#6
- Keywords has-unit-tests added
Return a filter in wp_get_attachment_image(). Props to @prionkor for https://github.com/WordPress/wordpress-develop/pull/440. I initialized $attachment
, add unit test, and filter docs.
Trac ticket: https://core.trac.wordpress.org/ticket/50801
This ticket was mentioned in Slack in #core by sisir. View the logs.
4 years ago
This ticket was mentioned in Slack in #core by metalandcoffee. View the logs.
4 years ago
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
4 years ago
#15
@
4 years ago
- Keywords commit added; dev-feedback removed
In the recent Media component meeting all agreed this is commit candidate. Marking commit so we don't forget. :)
This ticket was mentioned in Slack in #core by sncoker. View the logs.
4 years ago
#17
@
4 years ago
- Keywords commit removed
I made some changes to the patch that I'd like to get some outside looks at. I've been talking this through with @garrett-eclipse and we landed on the below proposed patch. I've removed the @since in the parent function's doc block because we are covering the documentation in the new filter.
I've also matched the passed attributes for the parent function in the new filter so folks can override any of them. Happy to hear any feedback on that.
I'm removing commit only because I don't want it to be committed before we all agree this approach is best. I'm also blocked at the moment by some local tests failing due to an unrelated change here: https://core.trac.wordpress.org/ticket/49558#comment:12
#20
@
4 years ago
- Keywords commit added
The new approach looks good. My only suggestion is to remove the added $attachment = ''
as it's no longer used outside of the if
block or by the new filter.
<?php function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '' ) { $attachment = '';
But this can be done when committing this patch.
This ticket was mentioned in Slack in #core-media by hellofromtonya. View the logs.
4 years ago
dream-encode commented on PR #447:
4 years ago
#23
Merged into WP Core in https://core.trac.wordpress.org/changeset/49234
dream-encode commented on PR #440:
4 years ago
#24
Merged into WP Core in https://core.trac.wordpress.org/changeset/49234
#25
@
4 years ago
- Keywords has-dev-note added; needs-dev-note removed
Dev note published: https://make.wordpress.org/core/2020/11/23/wordpress-and-php-8-0/
Add wp_get_attachment_image filter in output of wp_get_attachment_image() Trac ticket https://core.trac.wordpress.org/ticket/50801
Trac ticket: