Title: Prevent removing CSS rules
Last modified: December 22, 2019

---

# Prevent removing CSS rules

 *  Resolved [Spacetime](https://wordpress.org/support/users/spacetime/)
 * (@spacetime)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/)
 * How can I configure the plugin to not remove CSS rules from inline styles?

Viewing 13 replies - 1 through 13 (of 13 total)

 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12264044)
 * Hello [@spacetime](https://wordpress.org/support/users/spacetime/)
 * I am sorry about the issue you are experiencing and I am happy to help.
    Can 
   you please share so examples and your website URL so we can check this? Thank
   you!
 *  Thread Starter [Spacetime](https://wordpress.org/support/users/spacetime/)
 * (@spacetime)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12264429)
 * I experienced the problem on a test site that is not public.
 * The problem occurs when I use fragment caching with [AMP plugin](https://wordpress.org/plugins/amp/).
 * 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.
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12265178)
 * Hello [@spacetime](https://wordpress.org/support/users/spacetime/)
 * Thank you for the information. What settings do you have enabled in Performance
   >Minify under HTML minify and CSS minify?
    And does the issue persist if you 
   disable those two options? Thank you!
 *  Thread Starter [Spacetime](https://wordpress.org/support/users/spacetime/)
 * (@spacetime)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12265195)
 * Both are disabled.
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12265515)
 * Hello [@spacetime](https://wordpress.org/support/users/spacetime/)
 * Thank you for the information.
    So to confirm the issue persists if those two
   settings are disabled? Does the issue persist if you completely disable minify?
   Are you using any other minify plugin?
 *  Thread Starter [Spacetime](https://wordpress.org/support/users/spacetime/)
 * (@spacetime)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12265553)
 * 1. Yes.
 * 2. Yes.
 * 3. No other minify plugin.
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12266987)
 * Hello [@spacetime](https://wordpress.org/support/users/spacetime/)
 * Thank you for the info. It appears that you are not calling the class correctly.
   
   Have you tried E.G:
 *     ```
       <!-- mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> -->
       echo '<div class="test-w3tc">AMP TEST</div>';
       <!-- /mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> -->
       ```
   
 * Thanks!
 *  Thread Starter [Spacetime](https://wordpress.org/support/users/spacetime/)
 * (@spacetime)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12267018)
 * No, you are wrong.
 * After the code executes it will generate:
 * `<div class="test-w3tc">AMP TEST</div>`
 * What is wrong with this code?
 * I prepared a test code so you can reproduce the problem. It makes no sense to
   modify test code so the problem does not appear.
 * If you test with a code where the class name is present in the PHP code then 
   the problem does not appear. Please read my post above.
 * I would only like to prevent the plugin from removing CSS rules I create.
 * Here is another real example to reproduce the problem – use the same header style
   code:
 *     ```
       <!-- mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> -->
       echo base64_decode ('PGRpdiBjbGFzcz0idGVzdC13M3RjIj5BTVAgVEVTVDwvZGl2Pg==');
       <!-- /mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> -->
       ```
   
 *  Thread Starter [Spacetime](https://wordpress.org/support/users/spacetime/)
 * (@spacetime)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12277257)
 * Any solution?
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12279080)
 * Hello [@spacetime](https://wordpress.org/support/users/spacetime/)
 * We are unable to replicate this issue. W3 Total Cache does not remove CSS rules.
   Especially not if minify is not enabled!
 *  Thread Starter [Spacetime](https://wordpress.org/support/users/spacetime/)
 * (@spacetime)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12279086)
 * But have you tested together with AMP plugin?
    The CSS rule gets removed.
 * It could be AMP plugin, I just need your confirmation that is not W3TC that removes
   CSS rules.
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12279096)
 * Hello [@spacetime](https://wordpress.org/support/users/spacetime/)
 * Yes, all tested. W3 Total Cache does not remove CSS rules.
    Thank you!
 *  Thread Starter [Spacetime](https://wordpress.org/support/users/spacetime/)
 * (@spacetime)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12279099)
 * Great, thank you very much!

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Prevent removing CSS rules’ is closed to new replies.

 * ![](https://ps.w.org/w3-total-cache/assets/icon-256x256.png?rev=1041806)
 * [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/w3-total-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/w3-total-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/w3-total-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/w3-total-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/w3-total-cache/reviews/)

 * 13 replies
 * 2 participants
 * Last reply from: [Spacetime](https://wordpress.org/support/users/spacetime/)
 * Last activity: [6 years, 5 months ago](https://wordpress.org/support/topic/prevent-removing-css-rules/#post-12279099)
 * Status: resolved