Title: Purge cache function not working
Last modified: July 15, 2021

---

# Purge cache function not working

 *  Resolved [mellow1](https://wordpress.org/support/users/cdsigns/)
 * (@cdsigns)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/purge-cache-function-not-working/)
 * We have a woocommerce store with checkbox in the backend to open and close the
   store. Inside child-themes functions.php there is a function that checks the 
   box and adds appropriate class to body.
 * The checkbox-update and body class only show after we manually hit “Purge SG 
   Cache” from the backend.
 * We wish include this through the functions, but so far no luck. If we change 
   the checkbox, the bodyclass only shows after manual purge.
 * The snippet of the bodyclass code is below. Could you help us out, we are probably
   missing something here.
 * For testing purposes we added both the purge-codes you provided. But nothing 
   happens, unless we use the backend button to purge.
 *     ```
       //
       // add class on checkbox
       function my_body_classes( $classes ) {
   
       if (function_exists('sg_cachepress_purge_everything')) {
                   sg_cachepress_purge_everything();
           }
   
           if (function_exists('sg_cachepress_purge_cache')) {
                   sg_cachepress_purge_cache();
           }
   
       if( wfs_is_service_enabled()   ) {
       		$classes[] = 'StoreIsNOTServing';
       }	
       	return $classes;
   
       }
       add_filter( 'body_class','my_body_classes' );
       ```
   
    -  This topic was modified 4 years, 10 months ago by [mellow1](https://wordpress.org/support/users/cdsigns/).

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

 *  Plugin Author [Stanimir Stoyanov](https://wordpress.org/support/users/sstoqnov/)
 * (@sstoqnov)
 * SiteGround Representative
 * [4 years, 10 months ago](https://wordpress.org/support/topic/purge-cache-function-not-working/#post-14663721)
 * Hey [@cdsigns](https://wordpress.org/support/users/cdsigns/)
 * Just move the purge function before you return the changed classes.
 *     ```
       // add class on checkbox
       function my_body_classes( $classes ) {
       	if( wfs_is_service_enabled()   ) {
       		$classes[] = 'StoreIsNOTServing';
       	}
       	if (function_exists('sg_cachepress_purge_everything')) {
       		sg_cachepress_purge_everything();
       	}
       	return $classes;
   
       }
       add_filter( 'body_class','my_body_classes' );
       ```
   
 * Regards,
    Stanimir
 *  Thread Starter [mellow1](https://wordpress.org/support/users/cdsigns/)
 * (@cdsigns)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/purge-cache-function-not-working/#post-14663949)
 * Hi Stanimir,
 * Thank you so much for the amazingly fast reply and help.
    At first we did not
   notice a change, but we forgot to clear the browser cache for the admin (silly
   mistake) and now everything works like a charm!
 * Have a great day,
 * Best regards.
 *  Plugin Author [Hristo Pandjarov](https://wordpress.org/support/users/hristo-sg/)
 * (@hristo-sg)
 * SiteGround Representative
 * [4 years, 10 months ago](https://wordpress.org/support/topic/purge-cache-function-not-working/#post-14717864)
 * Awesome, glad that it’s now working fine for you 🙂 You can drop a [quick review for the plugin](https://wordpress.org/support/plugin/sg-cachepress/reviews/)
   if you have the time, that would be highly appreciated 🙂
 *  Thread Starter [mellow1](https://wordpress.org/support/users/cdsigns/)
 * (@cdsigns)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/purge-cache-function-not-working/#post-15058058)
 * Hi [@hristo-sg](https://wordpress.org/support/users/hristo-sg/) or [@sstoqnov](https://wordpress.org/support/users/sstoqnov/),
 * Recently we discovered that for one of our websites the code, you provided above
   does not seem to be working anymore.
 * if our client checks or unchecks the box in the backend, the cache is no longer
   purged within the function. We need to perform a manual purge with the button
   in the backend. We are using 6.0.3 of your SG Optimizer plugin.
 * Would you happen to have any idea what might be causing this?

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

The topic ‘Purge cache function not working’ is closed to new replies.

 * ![](https://ps.w.org/sg-cachepress/assets/icon-256x256.gif?rev=2971889)
 * [Speed Optimizer - The All-In-One Performance-Boosting Plugin](https://wordpress.org/plugins/sg-cachepress/)
 * [Support Threads](https://wordpress.org/support/plugin/sg-cachepress/)
 * [Active Topics](https://wordpress.org/support/plugin/sg-cachepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/sg-cachepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/sg-cachepress/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [mellow1](https://wordpress.org/support/users/cdsigns/)
 * Last activity: [4 years, 6 months ago](https://wordpress.org/support/topic/purge-cache-function-not-working/#post-15058058)
 * Status: resolved