Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created November 27, 2018 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hellofromtonya/67c6dbb2fe32eeb064445f55d6f5a6ee to your computer and use it in GitHub Desktop.
Save hellofromtonya/67c6dbb2fe32eeb064445f55d6f5a6ee to your computer and use it in GitHub Desktop.
Allow turning off native AMP when the URL includes a `non-amp` query string.
<?php
/**
* Allow turning off native AMP when the URL includes a `non-amp` query string.
*
* @package Non_AMP
* @author XWP, Google, StudioPress, and contributors
* @license GPL-2.0+
*
* @wordpress-plugin
* Plugin Name: Non-AMP
* Plugin URI: https://github.com/studiopress/genesis-amp
* Description: Disables AMP when a 'non-amp' query string exists.
* Version: 0.1.0
* Author: XWP, Google, StudioPress, and contributors
* Author URI: https://github.com/studiopress/genesis-amp/graphs/contributors
* Text Domain: genesis-amp
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* GitHub Plugin URI: https://github.com/studiopress/genesis-amp
* Requires PHP: 5.3.6
* Requires WP: 4.9
*/
/**
* Hook into `amp_is_enabled` filter. If the URL has `?non-amp`, then disable AMP.
*
* @param bool $is_enabled True by default.
*
* @return bool returns false if non-AMP is requested.
*/
add_filter( 'amp_is_enabled', function( $is_enabled ) {
// If the URL includes `non-amp`, then disable AMP.
if ( isset( $_GET['non-amp'] ) ) {
return false;
}
// Else, return the original incoming value.
return $is_enabled;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment