Index: branches/5.7/src/wp-includes/media.php =================================================================== --- branches/5.7/src/wp-includes/media.php (revision 50681) +++ branches/5.7/src/wp-includes/media.php (revision 50684) @@ -1870,4 +1870,9 @@ */ function wp_img_tag_add_loading_attr( $image, $context ) { + // Images should have source and dimension attributes for the `loading` attribute to be added. + if ( false === strpos( $image, ' src="' ) || false === strpos( $image, ' width="' ) || false === strpos( $image, ' height="' ) ) { + return $image; + } + /** * Filters the `loading` attribute value to add to an image. Default `lazy`. @@ -1890,9 +1895,4 @@ } - // Images should have source and dimension attributes for the `loading` attribute to be added. - if ( false === strpos( $image, ' src="' ) || false === strpos( $image, ' width="' ) || false === strpos( $image, ' height="' ) ) { - return $image; - } - return str_replace( ''; add_filter( 'wp_iframe_tag_add_loading_attr', '__return_false' ); + $iframe = wp_iframe_tag_add_loading_attr( $iframe, 'test' ); + + $this->assertNotContains( ' loading=', $iframe ); + } + + /** + * @ticket 52768 + */ + function test_wp_iframe_tag_add_loading_attr_skip_wp_embed() { + $iframe = ''; + $fallback = '
Fallback content.'; + $iframe = wp_filter_oembed_result( $fallback . $iframe, (object) array( 'type' => 'rich' ), 'https://www.example.com' ); + $iframe = wp_iframe_tag_add_loading_attr( $iframe, 'test' ); $this->assertNotContains( ' loading=', $iframe );