mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-13 21:30:26 +00:00
Media: Optimize images created in shortcodes.
This fixes an issue where images dynamically created during shortcode rendering (e.g., shortcode image galleries), were not getting image optimizations like `loading="lazy"` or `fetchpriority="hight"` applied. Note that even after this commit, shortcodes are processed after the main content images, which can affect the order in which optimizations are applied in content areas. Follow-up to [56037]. Props spacedmonkey, flixos90, thekt12, swissspidy, joemcgill. Fixes #58681. git-svn-id: https://develop.svn.wordpress.org/trunk@56214 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -5725,9 +5725,10 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) {
|
||||
|
||||
/*
|
||||
* The first elements in 'the_content' or 'the_post_thumbnail' should not be lazy-loaded,
|
||||
* as they are likely above the fold.
|
||||
* as they are likely above the fold. Shortcodes are processed after content images, so if
|
||||
* thresholds haven't already been met, apply the same logic to those as well.
|
||||
*/
|
||||
if ( 'the_content' === $context || 'the_post_thumbnail' === $context ) {
|
||||
if ( 'the_content' === $context || 'the_post_thumbnail' === $context || 'do_shortcode' === $context ) {
|
||||
// Only elements within the main query loop have special handling.
|
||||
if ( is_admin() || ! in_the_loop() || ! is_main_query() ) {
|
||||
$loading_attrs['loading'] = 'lazy';
|
||||
|
||||
Reference in New Issue
Block a user