<?php | |
/** | |
* AMP Suppress Eager Loading Images plugin bootstrap. | |
* | |
* @package Google\AMP_Suppress_Eager_Loading_Images | |
* @author Weston Ruter, Google | |
* @license GPL-2.0-or-later | |
* @copyright 2020 Google Inc. | |
* | |
* @wordpress-plugin | |
* Plugin Name: AMP Suppress Eager Loading Images | |
* Plugin URI: https://gist.github.com/westonruter/e019e53d4e34235907138eae31897e46 | |
* Description: Prevent images (such as featured images in the Twenty Twenty-One theme) from causing AMP validation errors for the loading=eager attribute. | |
* Version: 0.1 | |
* Author: Weston Ruter, Google | |
* Author URI: https://weston.ruter.net/ | |
* License: GNU General Public License v2 (or later) | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
* Gist Plugin URI: https://gist.github.com/westonruter/e019e53d4e34235907138eae31897e46 | |
*/ | |
add_action( | |
'wp', | |
function () { | |
if ( ! function_exists( 'amp_is_request' ) || ! amp_is_request() ) { | |
return; | |
} | |
add_filter( | |
'wp_get_attachment_image_attributes', | |
function ( $attr ) { | |
if ( isset( $attr['loading'] ) && 'eager' === $attr['loading'] ) { | |
unset( $attr['loading'] ); | |
} | |
return $attr; | |
} | |
); | |
} | |
); |
This comment has been minimized.
This comment has been minimized.
This should be made obsolete by ampproject/amp-wp#5721. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Installation instructions: https://gist.github.com/westonruter/6110fbc4bef0c4b8c021a112012f7e9c