Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active April 9, 2021 01:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/8d52c0b807e6dfbbdf2219622d0f4a7e to your computer and use it in GitHub Desktop.
Save westonruter/8d52c0b807e6dfbbdf2219622d0f4a7e to your computer and use it in GitHub Desktop.
<?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' );
}
@westonruter
Copy link
Author

@westonruter
Copy link
Author

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