Skip to content

Instantly share code, notes, and snippets.

@schlessera
Last active May 8, 2021 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save schlessera/4127ab30f4235f1acbc11e3eee77701a to your computer and use it in GitHub Desktop.
Save schlessera/4127ab30f4235f1acbc11e3eee77701a to your computer and use it in GitHub Desktop.
AMP Disable ES Modules
<?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