Ticket #44427: 44427.3.diff
File 44427.3.diff, 2.8 KB (added by , 18 months ago) |
---|
-
src/wp-includes/default-filters.php
176 176 add_filter( 'the_content', 'shortcode_unautop' ); 177 177 add_filter( 'the_content', 'prepend_attachment' ); 178 178 add_filter( 'the_content', 'wp_make_content_images_responsive' ); 179 add_filter( 'the_content', 'wp_lazy_load_content_media' ); 179 180 180 181 add_filter( 'the_excerpt', 'wptexturize' ); 181 182 add_filter( 'the_excerpt', 'convert_smilies' ); -
src/wp-includes/media.php
1013 1013 'alt' => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ), 1014 1014 ); 1015 1015 1016 /** This filter is documented in wp-includes/media.php */ 1017 if ( apply_filters( 'wp_lazy_load_content_media', true ) ) { 1018 $default_attr['loading'] = 'lazy'; 1019 } 1020 1016 1021 $attr = wp_parse_args( $attr, $default_attr ); 1017 1022 1018 1023 // Generate 'srcset' and 'sizes' if not already present. … … 1595 1600 } 1596 1601 1597 1602 /** 1603 * Filters 'img' and 'iframe' elements in post content to add 'loading' attributes. 1604 * 1605 * @since 5.4.0 1606 * 1607 * @param string $content The raw post content to be filtered. 1608 * @return string Converted content with 'loading' attributes added to images. 1609 */ 1610 function wp_lazy_load_content_media( $content ) { 1611 $tags = array( 'img', 'iframe' ); 1612 1613 /** 1614 * Filters whether media in post content should be lazy-loaded with 'loading' attributes. 1615 * 1616 * @since 5.4.0 1617 * 1618 * @param bool $enabled Whether to lazy-load content media. Default true. 1619 */ 1620 if ( ! apply_filters( 'wp_lazy_load_content_media', true ) ) { 1621 return $content; 1622 } 1623 1624 return preg_replace_callback( 1625 '/<(' . implode( '|', $tags ) . ') [^>]+>/', 1626 function( array $matches ) { 1627 if ( false === strpos( $matches[0], ' loading=' ) ) { 1628 $tag = $matches[1]; 1629 return str_replace( '<' . $tag . ' ', '<' . $tag . ' loading="lazy" ', $matches[0] ); 1630 } 1631 return $matches[0]; 1632 }, 1633 $content 1634 ); 1635 } 1636 1637 /** 1598 1638 * Adds a 'wp-post-image' class to post thumbnails. Internal use only. 1599 1639 * 1600 1640 * Uses the {@see 'begin_fetch_post_thumbnail_html'} and {@see 'end_fetch_post_thumbnail_html'} -
src/wp-includes/pluggable.php
2591 2591 'extra_attr' => '', 2592 2592 ); 2593 2593 2594 /** This filter is documented in wp-includes/media.php */ 2595 if ( apply_filters( 'wp_lazy_load_content_media', true ) ) { 2596 $defaults['loading'] = 'lazy'; 2597 } 2598 2594 2599 if ( empty( $args ) ) { 2595 2600 $args = array(); 2596 2601 }