Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active July 14, 2021 01:44
Show Gist options
  • Save westonruter/e588bd4ed1778799b19417c838eb5e5e to your computer and use it in GitHub Desktop.
Save westonruter/e588bd4ed1778799b19417c838eb5e5e to your computer and use it in GitHub Desktop.
<?php
/**
* Disable LiteSpeed Cache Comment plugin bootstrap.
*
* @package Disable_LiteSpeed_Cache_Comment
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2020 Google Inc.
*
* @wordpress-plugin
* Plugin Name: Disable LiteSpeed Cache Comment
* Plugin URI: https://gist.github.com/westonruter/e588bd4ed1778799b19417c838eb5e5e
* Description: This is needed on sites using the AMP plugin because LiteSpeed Cache by default injects an HTML comment at the end of JSON responses which breaks AMP validation requests.
* Version: 0.2
* 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
*/
add_filter( 'litespeed_comment', '__return_false' );
if ( ! defined( 'LSCACHE_ESI_SILENCE' ) ) {
define( 'LSCACHE_ESI_SILENCE', true );
}
@westonruter
Copy link
Author

@aboyinthebox
Copy link

Hi Tried to install the zip but Wordpress is giving error
The package could not be installed. No valid plugins were found.

Plugin installation failed.

Return to Plugin Installer

@westonruter
Copy link
Author

You can instead just download this file and put it into your wp-content/plugins directory.

@RahulGuptaAcademy
Copy link

Even its Not working ....

@JLHC
Copy link

JLHC commented Jun 9, 2020

It looks like this removed this line:-

<!-- Page generated by LiteSpeed Cache 3.2.1 on 2020-06-10 01:42:36 -->

But not this line:-

<!-- Page optimized by LiteSpeed Cache @2020-06-09 17:42:37 -->

UPDATE: Adding the following will remove the Page Optimized by comment:-

define( 'LSCACHE_ESI_SILENCE', true );

@westonruter
Copy link
Author

Thanks, I've updated the plugin to define that constant.

@westonruter
Copy link
Author

Note that this plugin should no longer be necessary once 1.6 is released, as the plugin will proactively strip such comments as of ampproject/amp-wp#4679.

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