#57086 closed enhancement (fixed)
Omit or filter decoding attribute in wp_get_attachment_image()
Reported by: | maximej | Owned by: | flixos90 |
---|---|---|---|
Milestone: | 6.2 | Priority: | normal |
Severity: | normal | Version: | 6.1 |
Component: | Media | Keywords: | has-patch has-unit-tests commit add-to-field-guide needs-dev-note |
Focuses: | performance | Cc: |
Description
With that changeset [53480], decoding="async"
is added by default to images from wp_get_attachment_image()
And there are no way to :
- either remove the decoding attribute
Unlike the loading attribute, passing decoding false in $attr of wp_get_attachment_image wouldn't omit it.
- or filtering it
the newly introduced filter wp_img_tag_add_decoding_attr
isn't treated here
In my case, I need to disable this and right now, I see no other options than overriding specific plugins functions or modifying media core file.
(I manage a website where this async decoding attribute causes erratic issues in which some images of the posts carousels are not loaded until a browser zoom or some other action).
Attachments (3)
Change History (19)
#2
follow-up:
↓ 5
@
2 years ago
- Focuses performance added
- Keywords needs-patch needs-unit-tests added
- Milestone changed from Awaiting Review to 6.2
Hi @maximej and welcome back to trac!
The decoding
attribute can be controlled via the wp_img_tag_add_decoding_attr
filter by returning a value of false
, you can see further documentation for the filter in the developer guide.
You can also control the default value by passing either false
, "async"
, "auto"
(the default value browsers use) or "sync"
as an attribute:
<?php echo wp_get_attachment_image( 19, 'thumbnail', false, array( 'decoding' => 'auto' ) );
However, passing false
displays the string as an empty attribute, decoding=""
, which I believe is a bug that ought to be fixed and the attribute removed from the HTML generated.
I've moved this on to the 6.2 milestone for visibility and added the performance focus as the bug was introduced in an earlier performance ticket.
This ticket was mentioned in PR #3633 on WordPress/wordpress-develop by @adamsilverstein.
2 years ago
#3
- Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
Trac ticket: https://core.trac.wordpress.org/ticket/57086
#4
@
2 years ago
57086.diff offers an approach that avoids adding the decoding attribute when passed as false or an empty string and also adds tests.
#5
in reply to:
↑ 2
@
2 years ago
Hi @peterwilsoncc, thanks for the consideration !
The
decoding
attribute can be controlled via thewp_img_tag_add_decoding_attr
filter by returning a value offalse
, you can see further documentation for the filter in the developer guide.
Unless I miss something, that filter has no effect on wp_get_attachment_image()
(in my tests and by seeing the code)
The patch submitted handles only the first part of the ticket.
Shouldn't we introduce that filter in that function too ?
#6
@
2 years ago
Shouldn't we introduce that filter in that function too ?
@maximej You should be able to use the wp_get_attachment_image_attributes
filter that runs later in this function to remove the attribute*. Adding another filter seems redundant.
Is the wp_get_attachment_image
function being called in a plugin you use or your own code?
(I manage a website where this async decoding attribute causes erratic issues in which some images of the posts carousels are not loaded until a browser zoom or some other action).
Can you elaborate on that a bit further? my understanding was the decoding="async" attribute is safe to use in every context. If not, I'd like to better understand the underlying issue. What code or plugin do you use to show post carousels? Do the issues happen in specific browsers or browser versions? can you share a link to a problematic URL?
@flixos90 commented on PR #3633:
2 years ago
#8
@adamsilverstein This PR is very close to commit. Any chance you can get back to it in the next few weeks so we can get it committed?
@flixos90 commented on PR #3633:
23 months ago
#10
@peterwilsoncc Would you be available for taking another look at this as well?
@flixos90 commented on PR #3633:
23 months ago
#13
Committed in https://core.trac.wordpress.org/changeset/55171
Mentioning original ticket/discussion as well #53232
I agree that issues are very unlikely to happen but I would have expected more control on it.
Moreover, some might prefer a minimalistic/by default HTML markup.