[wp-trac] [WordPress Trac] #58212: Improve clunky logic to inject `loading` attribute in the `get_the_post_thumbnail()` function

WordPress Trac noreply at wordpress.org
Thu Apr 27 20:53:28 UTC 2023


#58212: Improve clunky logic to inject `loading` attribute in the
`get_the_post_thumbnail()` function
-----------------------------+------------------------------------------
 Reporter:  flixos90         |      Owner:  flixos90
     Type:  enhancement      |     Status:  assigned
 Priority:  normal           |  Milestone:  6.3
Component:  Post Thumbnails  |    Version:
 Severity:  normal           |   Keywords:  needs-unit-tests needs-patch
  Focuses:  performance      |
-----------------------------+------------------------------------------
 The `get_the_post_thumbnail()` function contains a somewhat hacky
 workaround today to compute the `loading` attribute (via
 `wp_get_loading_attr_default()`. While it uses `wp_get_attachment_image()`
 for basically all its markup, the `loading` attribute is already
 calculated before, which works technically okay, but has several drawbacks
 - most importantly there is no context on other attributes available in
 that function, and there is a risk of potentially calling the function
 again for the same image which would skew the content media count.

 This logic should be changed so that the `wp_get_loading_attr_default()`
 function call from `wp_get_attachment_image()` is used, even when the
 latter is invoked by `get_the_post_thumbnail()`. We can apply use of the
 `being_fetch_post_thumbnail_html` and `being_fetch_post_thumbnail_html`
 actions to conditionally change the `$context` value passed to
 `wp_get_loading_attr_default()`, in a similar way to how they are already
 used today to add the `wp-post-image` CSS class to such image tags.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58212>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list