#59550 closed defect (bug) (fixed)
Attribute "loading" with value "lazy" is missing
Reported by: | r3dluke | Owned by: | joemcgill |
---|---|---|---|
Milestone: | 6.6 | Priority: | normal |
Severity: | normal | Version: | 6.3 |
Component: | Media | Keywords: | has-patch |
Focuses: | docs | Cc: |
Description
Hello,
we just encountered an error with the wp_get_attachment_image() function. Since version 6.3 the loading="lazy" attribute isn't present in the image tag anymore.
We upgraded the versions one after another and detected a change with the update on version 6.3. The documentation states "Defaults to 'lazy'" which is wrong now. This is a serious issue for the performance of many sites that rely on the default lazy loading behaviour by using wp_get_attachment_image().
For testing this we just echoed the result of wp_get_attachment_image() with an example static attachment ID from our media library.
Change History (11)
#1
follow-up:
↓ 2
@
11 months ago
- Keywords reporter-feedback added
- Owner set to joemcgill
- Severity changed from major to normal
- Status changed from new to reviewing
#2
in reply to:
↑ 1
@
11 months ago
Replying to joemcgill:
Hi @r3dluke, welcome to Trac. There have indeed been intentional changes to the way WordPress applies lazy loading to images since 6.3. For a full explanation of the changes, you can see https://make.wordpress.org/core/2023/07/13/image-performance-enhancements-in-wordpress-6-3/.
Thank you for pointing out the confusion with the documentation for
wp_get_attachment_image()
. You are correct that this is now not always accurate, depending on the context for which that function is called.
To better understand whether you are experiencing unexpected behavior, it would be useful to better understand the context where you are using that function and expecting lazy loading to automatically be applied.
Hello Joe,
thanks for your feedback. We use the function almost in all places where we need an image tag containing srcset and all the attributes. Our theme is object-oriented and component based. If you take a look at https://meisterplan.com/ you'll see a testimonial slider at the bottom of the page. When updating to WordPress 6.3 (and above), images in this slider will be loaded already at the top of the page because the loading="lazy" is now missing and I would have to add the attribute manually via the atts array.
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
5 months ago
This ticket was mentioned in PR #6416 on WordPress/wordpress-develop by @joemcgill.
5 months ago
#5
- Keywords has-patch added
This updates the docblock attributes for wp_get_attachment_image()
to account for attribute values that are being determined by wp_get_loading_optimization_attributes()
. Updates docs for $attr['loading']
and adds docs for $attr['fetchpriority']
.
Trac ticket: https://core.trac.wordpress.org/ticket/59550
#6
@
5 months ago
- Focuses docs added
- Keywords reporter-feedback removed
- Milestone changed from Awaiting Review to 6.6
- Status changed from reviewing to accepted
I've opened PR #6416 to improve the documentation for wp_get_attachment_image()
, which seems like a reasonable request given that the lack of clarity in the docs was also referenced in this comment on a duplicate ticket.
This ticket was mentioned in Slack in #core-performance by joemcgill. View the logs.
5 months ago
This ticket was mentioned in PR #6466 on WordPress/wordpress-develop by @joemcgill.
4 months ago
#8
This updates the docblock attributes for wp_get_attachment_image()
to account for attribute values that are being determined by wp_get_loading_optimization_attributes()
. Updates docs for $attr['loading']
and adds docs for $attr['fetchpriority']
.
Trac ticket: https://core.trac.wordpress.org/ticket/59550
Replaces #6416.
Hi @r3dluke, welcome to Trac. There have indeed been intentional changes to the way WordPress applies lazy loading to images since 6.3. For a full explanation of the changes, you can see https://make.wordpress.org/core/2023/07/13/image-performance-enhancements-in-wordpress-6-3/.
Thank you for pointing out the confusion with the documentation for
wp_get_attachment_image()
. You are correct that this is now not always accurate, depending on the context for which that function is called.To better understand whether you are experiencing unexpected behavior, it would be useful to better understand the context where you are using that function and expecting lazy loading to automatically be applied.