Title: AMP cache is not cleared
Last modified: November 6, 2020

---

# AMP cache is not cleared

 *  Resolved [René](https://wordpress.org/support/users/mobiflip/)
 * (@mobiflip)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/amp-cache-is-not-cleared/)
 * editing and saving a page does not clear the AMP cache of the page. posturl/amp

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

 *  Thread Starter [René](https://wordpress.org/support/users/mobiflip/)
 * (@mobiflip)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/amp-cache-is-not-cleared/#post-13629030)
 * i have tried to fix it that way, i think it works, but i do not know if it is
   optimal.
 *     ```
       function clear_post_cache_on_edit_post() {
           if ( class_exists( 'Cache_Enabler' ) ) {
               Cache_Enabler::clear_page_cache_by_url( get_permalink( $post_id ), 'dir' );
           }
       }
   
       add_action( 'edit_cpt_news', 'clear_post_cache_on_edit_post', 10, 2 );
       add_action( 'edit_post', 'clear_post_cache_on_edit_post', 10, 2 );
       ```
   
 *  Anonymous User 16850768
 * (@anonymized-16850768)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/amp-cache-is-not-cleared/#post-13674865)
 * You’re right, automatically clearing cached AMP pages was not taken into consideration
   yet. Let me think of what solution would be best to address this. Updates to 
   follow shortly.
 *  Anonymous User 16850768
 * (@anonymized-16850768)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/amp-cache-is-not-cleared/#post-13809107)
 * Adding such a feature to cover this type of handling won’t be added to the current
   branch (1.6) but it’s on our list to look back at in the future. As for now this
   could be handled with a custom function like the one below:
 *     ```
       add_action( 'cache_enabler_page_cache_cleared', 'clear_amp_page_cache' );
   
       function clear_amp_page_cache( $page_cleared_url ) {
   
           // prevent function from being ran more than once
           remove_action( 'cache_enabler_page_cache_cleared', 'clear_amp_page_cache' );
   
           // set clear URL with /amp appended (e.g. https://www.example.com/about/amp)
           $clear_url = trailingslashit( $page_cleared_url ) . 'amp';
   
           // clear AMP page cache
           do_action( 'cache_enabler_clear_page_cache_by_url', $clear_url );
       }
       ```
   

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

The topic ‘AMP cache is not cleared’ is closed to new replies.

 * ![](https://ps.w.org/cache-enabler/assets/icon.svg?rev=2442383)
 * [Cache Enabler](https://wordpress.org/plugins/cache-enabler/)
 * [Support Threads](https://wordpress.org/support/plugin/cache-enabler/)
 * [Active Topics](https://wordpress.org/support/plugin/cache-enabler/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cache-enabler/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cache-enabler/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: Anonymous User 16850768
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/amp-cache-is-not-cleared/#post-13809107)
 * Status: resolved