Title: Clear Elementor&#8217;s CSS and Data Cache
Last modified: January 5, 2024

---

# Clear Elementor’s CSS and Data Cache

 *  [ronr1999](https://wordpress.org/support/users/ronr1999/)
 * (@ronr1999)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/)
 * Love the concept of this plugin!
 * This is referring to Elementor’s clear_cache hook. It would be very helpful to
   have this added:
 * \Elementor\Plugin::instance()->files_manager->clear_cache();
 * [LINK](https://elementor.com/help/regenerate-css-data/)

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/page/2/?output_format=md)

 *  Thread Starter [ronr1999](https://wordpress.org/support/users/ronr1999/)
 * (@ronr1999)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17321590)
 * Looks like this addition to caching-plugins.php file will work:
 *     ```wp-block-code
       /**
        * Return an array of plugin slugs that exist on this install.
        * If $clear_cache is true or not set, run functions.
        */
       function ccfm_clear_addtional_cache( $clear_cache = true ) {
           $plugin_slugs = [];
   
           if ( class_exists( 'PremiumAddons\Admin\Includes\Admin_Helper' ) &&
                method_exists(PremiumAddons\Admin\Includes\Admin_Helper::class, 'get_instance') && 
                method_exists(PremiumAddons\Admin\Includes\Admin_Helper::class, 'delete_assets_options') ) {
                   $plugin_slugs[] = 'premium-addons-for-elementor';
                   if ( $clear_cache ) {
                       $admin_helper = PremiumAddons\Admin\Includes\Admin_Helper::get_instance();
                       $admin_helper->delete_assets_options();
                   }
           }
   
           // Check if Elementor is loaded
           if ( did_action( 'elementor/loaded' ) ) {
       	error_log("Elementor Clear Cache has Run!");
               // Automatically purge and regenerate the Elementor CSS cache
               \Elementor\Plugin::instance()->files_manager->clear_cache();
               $plugin_slugs[] = 'elementor';
           }	
   
           return $plugin_slugs; 
       }
       ```
   
 *  Thread Starter [ronr1999](https://wordpress.org/support/users/ronr1999/)
 * (@ronr1999)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17321771)
 * I see a problem. This Elementor Clear Cache needs to run BEFORE clearing any 
   page caching plugin.
 *  Plugin Author [webheadcoder](https://wordpress.org/support/users/webheadllc/)
 * (@webheadllc)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17325274)
 * Hi [@ronr1999](https://wordpress.org/support/users/ronr1999/),
 * Thanks for finding this cache clearing function! I don’t seem to have that option
   in my Elementor (free version) so I can’t try it out right now. Your code looks
   good, but are you saying it doesn’t work and it needs to be run before the other
   caching plugins? Why is that?
 *  Thread Starter [ronr1999](https://wordpress.org/support/users/ronr1999/)
 * (@ronr1999)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17326482)
 * Thanks for the response. I moved it to the **clear-cache-for-widgets.php** page
   and it’s working. It needs to clear the Elementor css files and then clear caching.
 *     ```wp-block-code
       function ccfm_clear_cache_for_all() {
   
       	// Check if Elementor is loaded
           if ( did_action( 'elementor/loaded' ) ) {
               // Automatically purge and regenerate the Elementor CSS cache
               \Elementor\Plugin::instance()->files_manager->clear_cache();
               $plugin_slugs[] = 'elementor';
           }	
   
           global $wp_fastest_cache, $kinsta_cache, $admin, $ccfm_source;
   
           if ( empty( $ccfm_source ) ) {
               $ccfm_source = '';
           }
       ```
   
 * When there is an Elementor plugin update it does a [Regenerate](https://elementor.com/help/regenerate-css-data/)
   but caching has not cleared. Regenerate removes all of the Elementor CSS files(
   wp-content/uploads/elementor/css) and on first page load it regenerates the files.
   If there is caching active, then the page will not recognize the new css files,
   especially if you’re doing css minification. So cache has to be cleared every
   time Elementor is updated.
 * It just occurred to me, is your code also clearing minification? I’ve used WP-
   Optimize with minification but am now turning that off and moving to WP Super
   Cache.
 * Thanks again, it would be awesome to have the incorporate in a new release of
   the plugin. I know the Elementor community would love you for it!
 *  Plugin Author [webheadcoder](https://wordpress.org/support/users/webheadllc/)
 * (@webheadllc)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17327179)
 * Thank you very much for the explanation and updated code. I’ll definitely be 
   adding this to the plugin after I try it out.
 * I just took a look at WP Optimize and it doesn’t look like it clears the minification.
   I’ll need to add that as well.
 *  Thread Starter [ronr1999](https://wordpress.org/support/users/ronr1999/)
 * (@ronr1999)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17327223)
 * If you have a test site, I’m happy to install a copy of Elementor Pro.
 *  Plugin Author [webheadcoder](https://wordpress.org/support/users/webheadllc/)
 * (@webheadllc)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17327783)
 * I found the setting and code in the free version so I’ll try it out first. Thanks
   for the offer though!
 *  Plugin Author [webheadcoder](https://wordpress.org/support/users/webheadllc/)
 * (@webheadllc)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17330681)
 * Could you try adding your code to the ccfm_clear_addtional_cache function again?
   I tried the following steps and it cleared the css cache. I tried with Breeze
   and WP Super Cache. Let me know if I’m missing anything.
    1. Rollback Elementor to a previous version (using WP Rollback plugin)
    2. Visit a public page edited with Elementor (this creates the css cache)
    3. Update Elementor
    4. CSS cache should be cleared.
 * I added one additional check in the code so it only runs when cache is meant 
   to be cleared:
 *     ```wp-block-code
       function ccfm_clear_addtional_cache( $clear_cache = true ) {
           $plugin_slugs = [];
   
   
       ...
   
   
       	// Check if Elementor is loaded
           if ( $clear_cache && did_action( 'elementor/loaded' ) ) {
               error_log('elementor loaded');
               // Automatically purge and regenerate the Elementor CSS cache
               \Elementor\Plugin::instance()->files_manager->clear_cache();
               $plugin_slugs[] = 'elementor';
           }
   
           return $plugin_slugs;
       }
       ```
   
 *  Thread Starter [ronr1999](https://wordpress.org/support/users/ronr1999/)
 * (@ronr1999)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17330786)
 * I found an easier way to test. I go into file manager and delete the css files
   here: /wp-content/uploads/elementor/css
 * This simulates what the Elementor community has been seeing for the past couple
   of years. This seems to happen when Elementor releases a new version. The web
   pages are missing its css so render is messed up.
 * I tried your above edits but doesn’t seem to work when css files are missing.
   My original fix – adding to: clear-cache-for-widgets.php > ccfm_clear_cache_for_all
   is working fine. Elementor Regenerate needs to run before clearing cache. Or 
   am I confused and your above code should also be installed… ?
    -  This reply was modified 2 years, 5 months ago by [ronr1999](https://wordpress.org/support/users/ronr1999/).
 *  Plugin Author [webheadcoder](https://wordpress.org/support/users/webheadllc/)
 * (@webheadllc)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17331646)
 * I think I see the issue. The ccfm_clear_cache_for_all function runs in the ‘shutdown’
   hook so if a function takes too long within a hook, the hook isn’t run due to
   time constraints.
 * You can add the code to the beginning or end of ccfm_clear_cache_for_all and 
   it will run. But if you add it in a function that gets called from a hook (i.
   e. in ccfm_clear_addtional_cache), it may not run. It depends on the caching 
   plugin.
   Can you try placing your code at the end of ccfm_clear_cache_for_all()?
   I want to make sure it works for you too.
 *  Thread Starter [ronr1999](https://wordpress.org/support/users/ronr1999/)
 * (@ronr1999)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17333217)
 * Yes, it’s working fine at the end of: ccfm_clear_cache_for_all 
 * Seems like winner!
 *  Thread Starter [ronr1999](https://wordpress.org/support/users/ronr1999/)
 * (@ronr1999)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17333266)
 * I thought of another enhancement that would be great. How about a log of when
   this is activated. I know that manually clicking on “Clear Cache for Me” gives
   the Success banner, but when it’s running in the background, it’s an unknown 
   if it’s working or not.
 *  Plugin Author [webheadcoder](https://wordpress.org/support/users/webheadllc/)
 * (@webheadllc)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17333724)
 * That’s great news… and yet not great news. so any hooks in that function are 
   not guaranteed to run.
 * I’ll think about the log. I have a last run time right now. I’m not sure if people
   would care about reviewing cache clearing activity. I get what you mean though,
   it’s hard to know when it’s doing its thing.
 * Thank you very much for trying it out and working through this with me. I’ll 
   have the code in the next update.
 *  Thread Starter [ronr1999](https://wordpress.org/support/users/ronr1999/)
 * (@ronr1999)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17333764)
 * I’ve test everything that I can think of and it’s working. The key is that this
   works when a plugin is updated – especially Elementor.
 * Again, thanks for all your help. I know that this will benefit a ton of folks–
   Elementor now has over 5 million plugin downloads. Yikes!
 * Ok, here’s my latest. As a test, I’m writing to the error_log and sending myself
   an email. Those are working.
 *     ```wp-block-code
       /**
        * Clear the caches!
        */
       function ccfm_clear_cache_for_all() {
   
           global $wp_fastest_cache, $kinsta_cache, $admin, $ccfm_source;
   
           if ( empty( $ccfm_source ) ) {
               $ccfm_source = '';
           }
   
           do_action( 'ccfm_clear_cache_for_me_before', $ccfm_source );
   
       	// Set the timezone to Pacific Standard Time (PST)
       	date_default_timezone_set('America/Los_Angeles');
   
       	// Check if Elementor is loaded
       	if (did_action('elementor/loaded')) {
       		// Automatically purge and regenerate the Elementor CSS cache
       		\Elementor\Plugin::instance()->files_manager->clear_cache();
       		$plugin_slugs[] = 'elementor';
   
       		// Log message
       		$timestamp = date("d-M-Y H:i:s T");
       		$log_message = "[{$timestamp}] Elementor Clear Cache has Run!";
       		error_log($log_message . PHP_EOL, 3, "/home/tfcahost/public_html/cache/error_log");
   
       		// Send email notification
       		$to = "me@gmail.com"; // recipient's email address
       		$subject = "Elementor Cache Cleared";
       		$message = "Elementor cache has been cleared at {$timestamp} PST.";
       		$headers = "From: an@examaple.com"; // Replace with the sender's email address
   
       		// Check if the email is sent successfully
       		if (mail($to, $subject, $message, $headers)) {
       			error_log("Email notification sent successfully." . PHP_EOL, 3, "/home/tfcahost/public_html/cache/error_log");
       		} else {
       			error_log("Failed to send email notification." . PHP_EOL, 3, "/home/tfcahost/public_html/cache/error_log");
       		}
       	}
       ```
   
 *  Thread Starter [ronr1999](https://wordpress.org/support/users/ronr1999/)
 * (@ronr1999)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/#post-17337056)
 * With my latest update, with outgoing emails, I’m feeling that it’s like a client’s
   website heartbeat. I manage 32 websites and these emails give me a sense of the
   overall pulse of these sites. Might be nice to have more details in the emails,
   like plugin updates, page/post updates, etc. I’ll have to look more closely at
   the code.

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/page/2/?output_format=md)

The topic ‘Clear Elementor’s CSS and Data Cache’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/clear-cache-for-widgets.svg)
 * [Clear Cache for Me](https://wordpress.org/plugins/clear-cache-for-widgets/)
 * [Support Threads](https://wordpress.org/support/plugin/clear-cache-for-widgets/)
 * [Active Topics](https://wordpress.org/support/plugin/clear-cache-for-widgets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/clear-cache-for-widgets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/clear-cache-for-widgets/reviews/)

 * 17 replies
 * 2 participants
 * Last reply from: [ronr1999](https://wordpress.org/support/users/ronr1999/)
 * Last activity: [2 years, 4 months ago](https://wordpress.org/support/topic/clear-elementors-css-and-data-cache/page/2/#post-17348076)
 * Status: not resolved