Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

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 westonruter/d18fd37fb9a58a26ae375a0cb9570831 to your computer and use it in GitHub Desktop.
Save westonruter/d18fd37fb9a58a26ae375a0cb9570831 to your computer and use it in GitHub Desktop.
<?php
/**
* AMP Workaround meta[http-equiv=Content-Type]
*
* @package AMP_Workaround_Meta_Content_Type
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2019 Google Inc.
*
* @wordpress-plugin
* Plugin Name: AMP Workaround meta[http-equiv=Content-Type]
* Description: Fix validation error caused by a theme using meta[http-equiv=Content-Type].
* Plugin URI: https://gist.github.com/westonruter/d18fd37fb9a58a26ae375a0cb9570831
* Version: 0.1.0
* 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/d18fd37fb9a58a26ae375a0cb9570831
*/
namespace AMP_Workaround_Meta_Content_Type;
add_filter(
'amp_content_sanitizers',
function ( $sanitizers ) {
if ( ! class_exists( 'AMP_Workaround_Meta_Content_Type_Sanitizer' ) ) {
class Meta_Content_Type_Sanitizer extends \AMP_Base_Sanitizer {
function sanitize() {
$xpath = new \DOMXPath( $this->dom );
foreach ( $xpath->query( '/html/head/meta[ @http-equiv ]' ) as $meta ) {
if ( strtolower( $meta->getAttribute( 'http-equiv' ) ) === 'content-type' ) {
$meta->parentNode->removeChild( $meta );
}
}
}
}
}
$sanitizers[ __NAMESPACE__ . '\Meta_Content_Type_Sanitizer' ] = [];
return $sanitizers;
}
);
@westonruter
Copy link
Author

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