diff --git a/wp-lazy-loading.php b/wp-lazy-loading.php index 6bfbca2..a89fe1e 100644 --- a/wp-lazy-loading.php +++ b/wp-lazy-loading.php @@ -32,10 +32,8 @@ function _wp_lazy_loading_initialize_filters() { // The following filters would be merged into core. foreach ( array( 'the_content', 'the_excerpt', 'comment_text', 'widget_text_content' ) as $filter ) { - // Before parsing blocks and shortcodes. - // TODO: Comments do not support images. Revisit. - // TODO: This should not exclude images from dynamic blocks and shortcodes. Look at fixing the filter priority. - add_filter( $filter, 'wp_add_lazy_load_attributes', 8 ); + // After parsing blocks and shortcodes. + add_filter( $filter, 'wp_add_lazy_load_attributes', 25 ); } // The following filters are only needed while this is a feature plugin. @@ -141,9 +139,32 @@ function wp_add_lazy_load_attributes( $content, $context = null ) { return preg_replace_callback( '/]+>/', - function( array $matches ) { + function( array $matches ) use( $content, $context ) { if ( ! preg_match( '/\sloading\s*=/', $matches[0] ) ) { - return str_replace( '