• Resolved René

    (@mobiflip)


    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é

    (@mobiflip)

    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)

    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)

    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.