This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Lozad | |
* Attribute replacement refernce from: https://gist.github.com/ahmadassaf/9332846 | |
*/ | |
function faster_replace_img_src( $content ){ | |
if ( function_exists( 'is_amp_endpoint' ) && ! is_amp_endpoint() ) { | |
$html = preg_replace_callback( '#(<img\s[^>]*src)="([^"]+)"#' , 'callback_img' , $content ); | |
$html = preg_replace( '/(<img\s[^>]*)class="(.*)"/', '$1 class="lozad $2"' , $html ); | |
$html = preg_replace( '/(<img\s[^>]*)srcset="(.*)"/', '$1 data-srcset="$2"' , $html ); |