Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add noloading to all images in an AMP page
<?php
/**
* Make sure that all <amp-img> elements have the noloading attribute.
*/
class Img_Noloading_Sanitizer extends AMP_Base_Sanitizer {
public function sanitize() {
foreach ( $this->dom->getElementsByTagName( 'amp-img' ) as $img ) {
$img->setAttribute( 'noloading', '' );
}
}
}
<?php
add_filter( 'amp_content_sanitizers', function( $sanitizers ) {
require_once __DIR__ . '/class-img-noloading-sanitizer.php';
return array_merge(
$sanitizers,
array(
'Img_Noloading_Sanitizer' => array(),
)
);
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment