Last active
December 21, 2020 00:30
-
-
Save westonruter/e019e53d4e34235907138eae31897e46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation instructions: https://gist.github.com/westonruter/6110fbc4bef0c4b8c021a112012f7e9c