-
-
Save westonruter/279bcb54336449ce55d8887fb0fcf5b9 to your computer and use it in GitHub Desktop.
AMP Disable ES Modules (unless enabled with query param)
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 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; | |
} | |
); | |
} |
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