From bb8ad05161c795da6f4d5f1f70a09f80ade14a01 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 7 Jul 2023 18:08:24 +0000 Subject: [PATCH] Media: Avoid programmatically created images within post content from incorrectly receiving `fetchpriority="high"`. Follow-up to [56037], as that changeset accidentally did not consider the changes made in [55825]: Images that are programmatically injected into post content (e.g. through a block, or shortcode, or any hook calling a function like `wp_get_attachment_image()`) must be treated as part of the whole post content blob since otherwise the heuristics for applying `fetchpriority="high"` and `loading="lazy"` are skewed by parsing certain images before others rather than sequentially parsing the entire post content. [55825] addressed that for lazy-loading, but when [56037] introduced `fetchpriority` support, the related refactor missed making the same consideration for that attribute. Props flixos90, spacedmonkey, thekt12, mukesh27. Fixes #58235. See #58089. Built from https://develop.svn.wordpress.org/trunk@56164 git-svn-id: http://core.svn.wordpress.org/trunk@55676 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 7 ++++--- wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index f8b0f9c1b1..234a826447 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -5666,11 +5666,12 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) { /* * Skip programmatically created images within post content as they need to be handled together with the other * images within the post content. - * Without this clause, they would already be counted below which skews the number and can result in the first - * post content image being lazy-loaded only because there are images elsewhere in the post content. + * Without this clause, they would already be considered below which skews the image count and can result in + * the first post content image being lazy-loaded or an image further down the page being marked as a high + * priority. */ if ( doing_filter( 'the_content' ) ) { - return $postprocess( $loading_attrs, true ); + return $loading_attrs; } // Conditionally skip lazy-loading on images before the loop. diff --git a/wp-includes/version.php b/wp-includes/version.php index 69bed8706b..287bdce857 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-beta3-56163'; +$wp_version = '6.3-beta3-56164'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.