diff --git a/includes/sanitizers/class-amp-core-theme-sanitizer.php b/includes/sanitizers/class-amp-core-theme-sanitizer.php index 55a9c3b63f1..20b1ee563cd 100644 --- a/includes/sanitizers/class-amp-core-theme-sanitizer.php +++ b/includes/sanitizers/class-amp-core-theme-sanitizer.php @@ -78,6 +78,7 @@ class AMP_Core_Theme_Sanitizer extends AMP_Base_Sanitizer { '//header[@id = "masthead"]//a[ contains( @class, "menu-scroll-down" ) ]', ), 'set_twentyseventeen_quotes_icon' => array(), + 'add_twentyseventeen_attachment_image_attributes' => array(), ), // Twenty Sixteen. @@ -344,6 +345,30 @@ public static function set_twentyseventeen_quotes_icon() { } ); } + /** + * Add filter to adjust the attachment image attributes to ensure attachment pages have a consistent rendering. + * + * This is only used in Twenty Seventeen. + * + * @since 1.0 + * @link https://github.com/WordPress/wordpress-develop/blob/ddc8f803c6e99118998191fd2ea24124feb53659/src/wp-content/themes/twentyseventeen/functions.php#L545:L554 + */ + public static function add_twentyseventeen_attachment_image_attributes() { + add_filter( 'wp_get_attachment_image_attributes', function ( $attr, $attachment, $size ) { + if ( ! is_attachment() ) { + return $attr; + } + + $sizes = wp_get_attachment_image_sizes( $attachment->ID, $size ); + if ( false !== $sizes ) { + $attr['layout'] = 'responsive'; + $attr['sizes'] = $sizes; + } + + return $attr; + }, 11, 3 ); + } + /** * Fix up core themes to do things in the AMP way. *