Automatically clear Elementor-generated CSS and cache files whenever a post, page, or custom post type is updated. This prevents outdated styles and removes the need to manually regenerate Elementor CSS after edits.
add_action( 'save_post', 'wpf_clear_elementor_cache_on_update', 20 );
function wpf_clear_elementor_cache_on_update( $post_id ) {
if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
return;
}
if ( class_exists( 'ElementorPlugin' ) ) {
ElementorPlugin::$instance->files_manager->clear_cache();
ElementorPlugin::$instance->posts_css_manager->clear_cache();
}
}