If you’re using the LiteSpeed Cache plugin with the AMP plugin on your WordPress site and it shows AMP Site Scanning Failed or AMP Validation Error, you’re not alone! Many users face this issue because the LiteSpeed cache plugin adds HTML comments to the page output, which can break AMP validation, especially when scanning JSON responses. This post will guide you through resolving this problem.
What Causes the AMP Site Scan to Fail?
The AMP site scanning failed because the LiteSpeed Cache appends HTML comments like:
<!-- Page generated by LiteSpeed Cache 6.5.1 on 2024-09-29 06:06:06 -->
These comments, including JSON responses, are injected into the page output, causing AMP site scans to fail due to invalid content. The AMP WordPress support form also discussed the same issue and solution.
Solution of AMP Site Scanning Failure:
To fix the scanning issue and AMP validation errors, you must prevent LiteSpeed Cache from adding these comments. Follow these steps:
1. Disable LiteSpeed Cache Comments: Add a code snippet to your theme’s functions.php (preferably in a child theme) or in a custom plugin using FTP or your cPanel.
add_filter( 'litespeed_comment', '__return_false' );
This will suppress the LiteSpeed Cache comments that break AMP scans.
2. Suppress ESI (Edge Side Includes) Output: If you’re facing AMP validation errors or dealing with dynamic content (like comments or user-specific data), you should also prevent LiteSpeed Cache from processing ESI blocks by adding the below code:
if (!defined('LSCACHE_ESI_SILENCE')) {
define('LSCACHE_ESI_SILENCE', true);
}
In addition to resolving site scan failures, this solution will fix AMP validation errors caused by LiteSpeed Cache.
Why Is This Necessary?
- LiteSpeed Cache HTML Comments: These comments help debug caching behavior but interfere with AMP compliance. By disabling them, your site will pass AMP validation without these conflicts.
- ESI Blocks: Edge Side Includes generating dynamic content that isn’t AMP-compliant. Silencing them ensures that LiteSpeed doesn’t output this content on AMP pages.
Alternative Solutions:
If you prefer not to use LiteSpeed Cache or if the issue persists, you can try switching to these caching plugins:
- WP Rocket (popular plugin, also AMP compatible)
- Breeze (compatible with this mini plugin or keep preloading disabled)
- Cache Enabler (minimal configuration and good for CDN service)
- WP-Optimize (good for database optimization that also has caching features)
- Speed Optimizer (recommended for SiteGround hosted site, don’t enable lazy loading).
Many users running AMP with LiteSpeed Cache face the same problem, but with this simple fix, you can ensure your AMP site passes validation and performs optimally. If you are still facing issues then contact AMP support.
At RankTiS, we provide comprehensive WordPress solutions, focusing on fixing common issues, optimizing site performance, and custom design. Our expert team ensures your site runs smoothly and looks professional. Whether you’re facing technical challenges or need a complete site overhaul, consider our customized WordPress solutions.
