Wp-rocket Lazyload
Modify attr when Lazyloading is activate on wp-rocket plugins
When lazy-loading is enabled (for example by WP Rocket), image URLs are stored in data-lazy-src / data-lazy-srcset attributes instead of src / srcset. You can tell the Weglot parser to detect and translate those attributes with the weglot_get_dom_checkers filter.
add_filter( 'weglot_get_dom_checkers', 'weglot_dom_check_data_lazy_src' );
function weglot_dom_check_data_lazy_src( $dom_checkers ) {
if ( ! class_exists( 'Img_Data_Lazy_Src' ) ) {
class Img_Data_Lazy_Src extends Weglot\Parser\Check\Dom\AbstractDomChecker {
const DOM = 'img';
const PROPERTY = 'data-lazy-src';
const WORD_TYPE = Weglot\Client\Api\Enum\WordType::IMG_SRC;
}
$dom_checkers[] = '\Img_Data_Lazy_Src';
}
if ( ! class_exists( 'Source_Data_Lazy_SrcSet' ) ) {
class Source_Data_Lazy_SrcSet extends Weglot\Parser\Check\Dom\AbstractDomChecker {
const DOM = 'source';
const PROPERTY = 'data-lazy-srcset';
const WORD_TYPE = Weglot\Client\Api\Enum\WordType::IMG_SRC;
}
$dom_checkers[] = '\Source_Data_Lazy_SrcSet';
}
return $dom_checkers;
}Last updated