Skip to content

Commit e3ec304

Browse files
westonruterCopilot
andauthored
Account for IMG as root block element
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 6e4e3bc commit e3ec304

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/wp-includes/block-supports/block-visibility.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,17 @@ function wp_render_block_visibility_support( $block_content, $block ) {
140140
if ( $processor->next_tag() ) {
141141
$processor->add_class( implode( ' ', $class_names ) );
142142
}
143+
$block_content = $processor->get_updated_html();
143144

144145
/*
145146
* Set all IMG tags to be `fetchpriority=auto` so that wp_get_loading_optimization_attributes() won't add
146-
* `fetchpriority=high` or increment the media count to affect whether subsequent IMG tags get `loading=lazy`.
147+
* `fetchpriority=high` or increment the media count to effect whether subsequent IMG tags get `loading=lazy`.
147148
*/
148-
while ( $processor->next_tag( 'IMG' ) ) {
149-
$processor->set_attribute( 'fetchpriority', 'auto' );
149+
$img_processor = new WP_HTML_Tag_Processor( $block_content );
150+
while ( $img_processor->next_tag( 'IMG' ) ) {
151+
$img_processor->set_attribute( 'fetchpriority', 'auto' );
150152
}
151-
$block_content = $processor->get_updated_html();
153+
$block_content = $img_processor->get_updated_html();
152154
}
153155
}
154156

0 commit comments

Comments
 (0)