Last active
May 8, 2021 17:27
-
-
Save schlessera/4127ab30f4235f1acbc11e3eee77701a to your computer and use it in GitHub Desktop.
AMP Disable ES Modules
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 Disable ES Modules. | |
* | |
* @package AMP_Disable_ESM | |
* @author Alain Schlesser <alain.schlesser@gmail.com> | |
* @link https://gist.github.com/schlessera/4127ab30f4235f1acbc11e3eee77701a | |
* @license GPL-2.0-or-later | |
* | |
* @wordpress-plugin | |
* Plugin Name: AMP Disable ES Modules | |
* Plugin URI: https://gist.github.com/schlessera/4127ab30f4235f1acbc11e3eee77701a | |
* Description: Disable the use of ES modules by the AMP Optimizer via <code>amp_esm=0</code>. | |
* Version: 0.1 | |
* Author: Alain Schlesser <alain.schlesser@gmail.com> | |
* Author URI: https://alainschlesser.com/ | |
* License: MIT | |
* Gist Plugin URI: https://gist.github.com/schlessera/4127ab30f4235f1acbc11e3eee77701a | |
*/ | |
use AmpProject\Optimizer\Transformer\RewriteAmpUrls; | |
use AmpProject\Optimizer\Configuration\RewriteAmpUrlsConfiguration; | |
if ( isset( $_GET['amp_esm'] ) && false === rest_sanitize_boolean( $_GET['amp_esm'] ) ) { | |
add_filter( 'amp_optimizer_config', static function ( $config ) { | |
$config[ RewriteAmpUrls::class ][ RewriteAmpUrlsConfiguration::ESM_MODULES_ENABLED ] = false; | |
return $config; | |
} ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment