Close Menu
  • Home
  • Learn
  • Web Hosting
  • Website Optimization
  • Elementor
  • Tech Jobs
  • Consultations NEW
  • More
    • About
    • Contact
    • Artificial Intelligence
    • CDN
    • Deals & Discounts
    • eCommerce
    • Movies & TV Shows
    • MyListing
    • Small Business
    • Themes & Templates
    • Tools
      • Internet Speedtest
      • VPN
    • Voxel
    • VPN
    • Web Hosting Services
    • Web Security
    • WooCommerce
    • WordPress
Tags
Analytics Archive auctions wordpress theme Backups Business business directory ChatGPT city guide classified Code Editors cPanel Crocoblock Deals directory Discord Discounts dokan ecommerce education wordpress theme Featured FTP Generative AI Google Cloud Google DeepMind grocery multivendor learning management system LiteSpeed Cache lms marketplace Matomo multi-vendor Opera PHP Plugin Update responisve shopify theme Sale SEO shop SSH Trending Updates Web Hosting woocommerce wordpress World Backup Day
Facebook X (Twitter) YouTube
Binary Blackboard
  • Home
  • Learn
  • Web Hosting
    LiteSpeed Cache vs WP Rocket

    LiteSpeed Cache vs WP Rocket

    August 3, 2023
    Storage racks aligned in a computer server room.

    Shared Web Hosting: Is It the Right Choice for Your Website?

    June 10, 2023
    Memorial day seal with the word deal next to it

    Memorial Day Weekend Deals

    May 25, 2023
    Woman holding a laptop as she works on web hosting servers

    Crucial Things to Know When Choosing Web Hosting Services

    March 27, 2023
    This is the A2 Hosting logo. It says “A2 Hosting Our Speed Your Success.”

    Switching to cPanel’s Jupiter Theme

    March 27, 2023
  • Website Optimization
    Logo for Elementor

    Automatically Clear Elementor Cache and Regenerate CSS

    July 25, 2023
    Screenshot of a macOS shortcut

    Website Speedtest macOS Shortcuts

    June 24, 2023
    New method accelerates data retrieval in huge databases

    New method accelerates data retrieval in huge databases

    March 15, 2023
    LiteSpeed Cache plugin settings dashboard

    LiteSpeed Cache Settings for Voxel

    March 9, 2023
    Logo for Redis Cache

    Are You Using Redis Cache on Your Website?

    March 8, 2023
  • Elementor
    Logo for Elementor

    Automatically Clear Elementor Cache and Regenerate CSS

    July 25, 2023
    Elementor helpful tips

    Unlock the Full Potential of Elementor with These 10 Advanced Tips

    May 20, 2023
    Logo for Elementor

    Master the Art of Web Design with Elementor Pro

    May 20, 2023
    Elementor CSS Print Method Settings

    What Is CSS Print Method in the Elementor Settings? Which Should I Choose?

    May 18, 2023
    Widgets for the Elementor page builder

    Remove Unused Elementor Widgets

    January 15, 2023
  • Tech Jobs
  • Consultations NEW
  • More
    • About
    • Contact
    • Artificial Intelligence
    • CDN
    • Deals & Discounts
    • eCommerce
    • Movies & TV Shows
    • MyListing
    • Small Business
    • Themes & Templates
    • Tools
      • Internet Speedtest
      • VPN
    • Voxel
    • VPN
    • Web Hosting Services
    • Web Security
    • WooCommerce
    • WordPress
Binary Blackboard
Home»Elementor»Automatically Clear Elementor Cache and Regenerate CSS
Elementor

Automatically Clear Elementor Cache and Regenerate CSS

July 25, 20233 Mins Read730
Facebook Twitter Pinterest LinkedIn Email WhatsApp Reddit
Logo for Elementor

** Updated July 25, 2023 **

On certain themes, you may encounter issues where you have to Regenerate CSS & Data in the Elementor tools. If you hate having to go to the Elementor tools to regenerate the files and data, then these handy functions will help.

Elementor had updated the hook to clear the Elementor cache. it now uses:

				
					\Elementor\Plugin::$instance->posts_css_manager->clear_cache();
				
			

I have also added a Quicklink on the WordPress top bar that can clear the Elementor cache, and regenerate the CSS. This is great so you don’t have to navigate to the Elementor tools to do this. Simply click on the link to clear the cache.

So now my updated code clears the Elementor cache every time you save your changes in the Elementor editor and also does it from the top of the admin dashboard.

I also included code to add the CSS in a separate file. Create a file in the same directory as your child’s function.php file, and name it “binarybb-styles.css”

That way if I share more cool snippets, we can just add the CSS to that file.

So in the CSS file, you will add the following CSS:

				
					/* ***** Change the background color and padding to make it look like a button */
#wp-admin-bar-binarybb_regenerate_elementor_css > a {
    background-color: #0073aa;
    color: #ffffff;
    padding: 5px 10px;
    border-radius: 2px;
}

/* ***** Change the hover color */
#wp-admin-bar-binarybb_regenerate_elementor_css:hover > a {
    background-color: #008ec2;
}
				
			

Minified version of the code above

				
					#wp-admin-bar-binarybb_regenerate_elementor_css>a{background-color:#0073aa;color:#fff;padding:5px 10px;border-radius:2px}#wp-admin-bar-binarybb_regenerate_elementor_css:hover>a{background-color:#008ec2}
				
			

Here is the updated code you will add to your child theme’s function.php file:

				
					// ***** Enqueue the Binary Blackboard CSS file.
function binarybb_enqueue_custom_admin_styles() {
    wp_enqueue_style( 'bb-admin-styles', get_stylesheet_directory_uri() . '/binarybb-styles.css', [], '1.0.0' );
}
add_action( 'admin_enqueue_scripts', 'binarybb_enqueue_custom_admin_styles' );


// ***** Clear Elementor Cache after saving/updating.
function binarybb_clear_elementor_cache() {
    
    if ( did_action( 'elementor/loaded' ) ) {
        \Elementor\Plugin::$instance->posts_css_manager->clear_cache();
    }
}
add_action('elementor/editor/after_save', 'binarybb_clear_elementor_cache');


// ***** Handles the action to clear the cache with the admin top bar link.
function binarybb_regenerate_elementor() {
    
    check_admin_referer( 'binarybb_regenerate_elementor_action' );
    
    if ( current_user_can( 'manage_options' ) && did_action( 'elementor/loaded' ) ) {
        \Elementor\Plugin::instance()->files_manager->clear_cache();
        wp_redirect( add_query_arg( 'binarybb_notice', 'elementor_regenerated', wp_get_referer() ) );
        exit;
    }
    
    wp_safe_redirect( wp_get_referer() );
    exit;
}
add_action( 'admin_post_binarybb_regenerate_elementor', 'binarybb_regenerate_elementor' );


// ***** Add the quicklink to the admin bar
function binarybb_custom_admin_bar_link() {
    global $wp_admin_bar;
    
    if ( current_user_can( 'manage_options' ) ) {
        $wp_admin_bar->add_menu( array(
            'id' => 'binarybb_regenerate_elementor_css',
            'title' => '<span class="ab-icon dashicons dashicons-image-rotate"></span><span class="ab-label">Clear Elementor Cache</span>',
            'href' => wp_nonce_url( admin_url( 'admin-post.php?action=binarybb_regenerate_elementor' ), 'binarybb_regenerate_elementor_action' )
        ) );
    }
}
add_action( 'admin_bar_menu', 'binarybb_custom_admin_bar_link', 100 );


// ***** Display a notice when the regeneration is complete.
function binarybb_show_admin_notice() {
    if ( isset( $_GET['binarybb_notice'] ) && $_GET['binarybb_notice'] === 'elementor_regenerated' ) {
        $share_url = urlencode(get_permalink());
        $share_text = urlencode('Automatically cleared the Elementor cache, <a href="https://binaryblackboard.com/elementor-cache-regenerate-css/" target="_blank">here is how to do it.</a>');
        echo '<div class="notice notice-success is-dismissible">
            <p>Elementor cache cleared & CSS Regenerated! Share the BinaryBlackboard love! &nbsp; 
                <a href="https://twitter.com/intent/tweet?url=&#039; . $share_url . &#039;&amp;text=&#039; . $share_text . &#039;" target="_blank" class="button" rel="nofollow noopener">Tweet(X) this!</a> 
                <a href="https://www.facebook.com/sharer/sharer.php?u=&#039; . $share_url . &#039;" target="_blank" class="button" rel="nofollow noopener">Share on Facebook!</a>
            </p>
        </div>';
    }
}
add_action( 'admin_notices', 'binarybb_show_admin_notice' );
				
			

Please contact me if you encounter any issues 

Bonus tip

You can also add cache
functions from your other caching plugins

Share. Facebook Twitter Pinterest LinkedIn Email WhatsApp Reddit

Related Posts

Wordpress 6.3 Lionel

WordPress Update 6.3 “Lionel” is out

Programming code of PHP for WordPress

Which PHP Version Should You Use for WordPress in 2023?

LiteSpeed Cache vs WP Rocket

LiteSpeed Cache vs WP Rocket

Leave A Reply Cancel Reply

You must be logged in to post a comment.

Menu
  • About
  • Contact
  • Developer Tools
  • Deals & Discounts
  • Sitemap
  • Privacy Policy
  • Terms of Service
Tags
Analytics Archive auctions wordpress theme Backups Business business directory ChatGPT city guide classified Code Editors cPanel Crocoblock Deals directory Discord Discounts dokan ecommerce education wordpress theme Featured FTP Generative AI Google Cloud Google DeepMind grocery multivendor learning management system LiteSpeed Cache lms marketplace Matomo multi-vendor Opera PHP Plugin Update responisve shopify theme Sale SEO shop SSH Trending Updates Web Hosting woocommerce wordpress World Backup Day
Facebook X (Twitter) YouTube
  • Privacy Policy
  • Terms of Service
Copyright © 2025 - binaryBlackboard.

Type above and press Enter to search. Press Esc to cancel.