@@ -6115,7 +6115,6 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) {
61156115 * on an IMG following any number of initial IMGs with `fetchpriority=auto` since those initial images may not
61166116 * be displayed.
61176117 */
6118- $ maybe_in_viewport = true ;
61196118
61206119 // Preserve fetchpriority=auto.
61216120 $ loading_attrs ['fetchpriority ' ] = 'auto ' ;
@@ -6195,16 +6194,20 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) {
61956194 /*
61966195 * If flag was set based on contextual logic above, increase the content
61976196 * media count, either unconditionally, or based on whether the image size
6198- * is larger than the threshold.
6197+ * is larger than the threshold. This does not apply when the IMG has
6198+ * fetchpriority=auto because it may be conditionally displayed by viewport
6199+ * size.
61996200 */
6200- if ( $ increase_count ) {
6201- wp_increase_content_media_count ();
6202- } elseif ( $ maybe_increase_count ) {
6203- /** This filter is documented in wp-includes/media.php */
6204- $ wp_min_priority_img_pixels = apply_filters ( 'wp_min_priority_img_pixels ' , 50000 );
6205-
6206- if ( $ wp_min_priority_img_pixels <= $ attr ['width ' ] * $ attr ['height ' ] ) {
6201+ if ( 'auto ' !== $ existing_fetchpriority ) {
6202+ if ( $ increase_count ) {
62076203 wp_increase_content_media_count ();
6204+ } elseif ( $ maybe_increase_count ) {
6205+ /** This filter is documented in wp-includes/media.php */
6206+ $ wp_min_priority_img_pixels = apply_filters ( 'wp_min_priority_img_pixels ' , 50000 );
6207+
6208+ if ( $ wp_min_priority_img_pixels <= $ attr ['width ' ] * $ attr ['height ' ] ) {
6209+ wp_increase_content_media_count ();
6210+ }
62086211 }
62096212 }
62106213
0 commit comments