Last active
April 9, 2021 01:03
-
-
Save westonruter/8d52c0b807e6dfbbdf2219622d0f4a7e 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 Enable SSR | |
* | |
* @package AMP_Enable_SSR | |
* @author Weston Ruter, Google | |
* @link https://gist.github.com/westonruter/8d52c0b807e6dfbbdf2219622d0f4a7e | |
* @license GPL-2.0-or-later | |
* @copyright 2019 Google Inc. | |
* | |
* @wordpress-plugin | |
* Plugin Name: AMP Enable SSR | |
* Plugin URI: https://gist.github.com/westonruter/8d52c0b807e6dfbbdf2219622d0f4a7e | |
* Description: Allow the Optimizer to be disabled from doing server-side-rendering (SSR) on AMP pages. To selectively disable, add amp_ssr=false to the URL. This is useful for debugging. | |
* Version: 0.4 | |
* 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/8d52c0b807e6dfbbdf2219622d0f4a7e | |
*/ | |
if ( ! isset( $_GET['amp_ssr'] ) || rest_sanitize_boolean( $_GET['amp_ssr'] ) ) { | |
add_filter( 'amp_enable_ssr', '__return_true' ); | |
} else { | |
add_filter( 'amp_enable_ssr', '__return_false' ); | |
} |
Note: Formerly this plugin was disabling the Optimizer as a whole, but this was excessive. So it has been re-scoped to just disable server-side-rendering (SSR). This is useful as a workaround for ampproject/amp-wp#4491.
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