(?# match the whole img tag ) [^>]*) (?# the opening of the img and some optional attributes ) ( (?# match a class attribute followed by some optional ones and the src attribute ) class=["\'](?P.*?(?:wp-image-|wp-post-image)[^>"\']*)["\'] (?P[^>]*) src=["\'](?P[^>"\']*)["\'] | (?# match same as before, but with the src attribute before the class attribute ) src=["\'](?P[^>"\']*)["\'] (?P[^>]*) class=["\'](?P.*?(?:wp-image-|wp-post-image)[^>"\']*)["\'] ) (?P[^>]*) (?# match any additional optional attributes ) (?P\/?)> (?# match the closing of the img tag with or without a self closing slash ) )/x', 'joy_replace_images', $content ); } /** * The callback function for the preg_match_callback to modify the img tags. * * @since 1.0.0 * * @param array $matches The regex matches. * * @return string The modified content string. */ function joy_replace_images( $matches ) { /* Empty gif */ $null = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='; // Return unmodified image if the "data skip" attribute was found or the image has already been processed. if ( false !== strpos( $matches['all'], 'data-image-lazy="exclude"' ) || false !== strpos( $matches['class1'] . $matches['class2'], 'crazy_lazy' ) ) { return $matches['all']; } else { return ''; } }