I experienced the problem on a test site that is not public.
The problem occurs when I use fragment caching with AMP plugin.
I insert inline CSS into header. This is then placed into <style amp-custom="">
by AMP plugin.
All the CSS rules used only inside code generated by PHP code of fragment caching are removed.
This can easily be reproduced.
Configure W3TC to use fragment caching and put some short piece of code on the page, for example (you can replace php code with W3TC_DYNAMIC_SECURITY with your ID):
<!-- mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> -->
echo '<div class="test-', 'w3tc">AMP TEST</div>';
<!-- /mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> -->
and put this code into header:
<style>
.test-w3tc {
background: #0ff;
}
</style>
It seems that since class test-w3tc
is not present in the HTML code (split into two parts – before processed by W3TC) the CSS rule for .test-w3tc
is removed on AMP pages.
I’m using fragment caching a lot and the CSS is dynamically generated.
Now I’m not sure whether the CSS code is removed by AMP plugin or W3TC.
Since W3TC has many options to optimize CSS I was wondering if it also “optimizes” CSS.
If not, then it must be the AMP plugin that removes CSS rules.
Anyway, I need to find a solution.
Please advise.