Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AMP Disable ES Modules (unless enabled with query param)
<?php
/**
* AMP Disable ES Modules by Default plugin.
*
* @package AMP_Disable_ESM
* @author Weston Ruter
* @link https://gist.github.com/westonruter/279bcb54336449ce55d8887fb0fcf5b9
* @license GPL-2.0-or-later
*
* @wordpress-plugin
* Plugin Name: AMP Disable ES Modules by Default
* Plugin URI: https://gist.github.com/westonruter/279bcb54336449ce55d8887fb0fcf5b9
* Description: Disable the use of ES modules by the AMP Optimizer unless a <code>amp_optimizer_config</code> query parameter is provided to allow them.
* Version: 0.1
* Author: Weston Ruter
* Author URI: https://weston.ruter.net/
* License: MIT
* Gist Plugin URI: https://gist.github.com/westonruter/279bcb54336449ce55d8887fb0fcf5b9
*/
use AmpProject\Optimizer\Transformer\RewriteAmpUrls;
use AmpProject\Optimizer\Configuration\RewriteAmpUrlsConfiguration;
if ( ! isset( $_GET['amp_esm_enabled'] ) ) {
add_filter(
'amp_optimizer_config',
static function ( $config ) {
$config[ RewriteAmpUrls::class ][ RewriteAmpUrlsConfiguration::ESM_MODULES_ENABLED ] = false;
return $config;
}
);
}
@westonruter

This comment has been minimized.

Copy link
Owner Author

@westonruter westonruter commented May 8, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment