From ed4e1b061ea7404c4d662163e244ce0a1c28fb2a Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 8 Mar 2026 18:34:48 -0700 Subject: [PATCH 1/4] Add fetchpriority=low to IMG tags in blocks with conditional viewport visibility --- lib/block-supports/block-visibility.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/block-supports/block-visibility.php b/lib/block-supports/block-visibility.php index dd3e214fd08ca8..1d3724f8fdc119 100644 --- a/lib/block-supports/block-visibility.php +++ b/lib/block-supports/block-visibility.php @@ -137,8 +137,16 @@ function gutenberg_render_block_visibility_support( $block_content, $block ) { $processor = new WP_HTML_Tag_Processor( $block_content ); if ( $processor->next_tag() ) { $processor->add_class( implode( ' ', $class_names ) ); - $block_content = $processor->get_updated_html(); } + + /* + * Set all IMG tags to be `fetchpriority=auto` so that wp_get_loading_optimization_attributes() won't add + * `fetchpriority=high` or increment the media count to effect whether subsequent IMG tags get `loading=lazy`. + */ + while ( $processor->next_tag( 'IMG' ) ) { + $processor->set_attribute( 'fetchpriority', 'auto' ); + } + $block_content = $processor->get_updated_html(); } } From 7f663c398c245104eb3601aa876e1d202645c4d2 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 8 Mar 2026 19:22:09 -0700 Subject: [PATCH 2/4] Add backport changelog --- backport-changelog/7.0/11196.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 backport-changelog/7.0/11196.md diff --git a/backport-changelog/7.0/11196.md b/backport-changelog/7.0/11196.md new file mode 100644 index 00000000000000..2c53419b6785f0 --- /dev/null +++ b/backport-changelog/7.0/11196.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/11196 + +* https://github.com/WordPress/gutenberg/pull/76302 From fa0522f57717f80621683b4ae0eb02268ac92e38 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 8 Mar 2026 20:05:56 -0700 Subject: [PATCH 3/4] Reuse HTML Tag Processor --- lib/block-supports/block-visibility.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/block-supports/block-visibility.php b/lib/block-supports/block-visibility.php index 1d3724f8fdc119..cd0aa3db480085 100644 --- a/lib/block-supports/block-visibility.php +++ b/lib/block-supports/block-visibility.php @@ -137,16 +137,18 @@ function gutenberg_render_block_visibility_support( $block_content, $block ) { $processor = new WP_HTML_Tag_Processor( $block_content ); if ( $processor->next_tag() ) { $processor->add_class( implode( ' ', $class_names ) ); - } - /* - * Set all IMG tags to be `fetchpriority=auto` so that wp_get_loading_optimization_attributes() won't add - * `fetchpriority=high` or increment the media count to effect whether subsequent IMG tags get `loading=lazy`. - */ - while ( $processor->next_tag( 'IMG' ) ) { - $processor->set_attribute( 'fetchpriority', 'auto' ); + /* + * Set all IMG tags to be `fetchpriority=auto` so that wp_get_loading_optimization_attributes() won't add + * `fetchpriority=high` or increment the media count to effect whether subsequent IMG tags get `loading=lazy`. + */ + do { + if ( 'IMG' === $processor->get_tag() ) { + $processor->set_attribute( 'fetchpriority', 'auto' ); + } + } while ( $processor->next_tag() ); + $block_content = $processor->get_updated_html(); } - $block_content = $processor->get_updated_html(); } } From 6fedb396817bad7b60d60e86a9db9992770e9f97 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 8 Mar 2026 21:21:34 -0700 Subject: [PATCH 4/4] Use affect instead of effect Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- lib/block-supports/block-visibility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/block-supports/block-visibility.php b/lib/block-supports/block-visibility.php index cd0aa3db480085..6bbce6b15cfb15 100644 --- a/lib/block-supports/block-visibility.php +++ b/lib/block-supports/block-visibility.php @@ -140,7 +140,7 @@ function gutenberg_render_block_visibility_support( $block_content, $block ) { /* * Set all IMG tags to be `fetchpriority=auto` so that wp_get_loading_optimization_attributes() won't add - * `fetchpriority=high` or increment the media count to effect whether subsequent IMG tags get `loading=lazy`. + * `fetchpriority=high` or increment the media count to affect whether subsequent IMG tags get `loading=lazy`. */ do { if ( 'IMG' === $processor->get_tag() ) {