Make WordPress Core

Opened 8 months ago

Closed 3 weeks ago

Last modified 3 weeks ago

#59550 closed defect (bug) (fixed)

Attribute "loading" with value "lazy" is missing

Reported by: r3dluke's profile r3dluke Owned by: joemcgill's profile 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: @joemcgill
8 months ago

  • Keywords reporter-feedback added
  • Owner set to joemcgill
  • Severity changed from major to normal
  • Status changed from new to reviewing

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.

#2 in reply to: ↑ 1 @r3dluke
8 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.


6 weeks ago

#4 @joedolson
6 weeks ago

#59421 was marked as a duplicate.

This ticket was mentioned in PR #6416 on WordPress/wordpress-develop by @joemcgill.


6 weeks 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 @joemcgill
6 weeks 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.


6 weeks ago

This ticket was mentioned in PR #6466 on WordPress/wordpress-develop by @joemcgill.


4 weeks 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.

@joemcgill commented on PR #6466:


4 weeks ago
#9

@dmsnell I added c20e580 to address your previous PR comments here.

#10 @joemcgill
3 weeks ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 58110:

Docs: Update docblock for wp_get_attachment_image() attributes.

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'].

Props joemcgill, dmsnell.
Fixes #59550.

Note: See TracTickets for help on using tickets.