Fix for WP SUPER CACHE home not refreshing

WP SUPER CACHE is one of the most used WordPress plugin for cache, but probably there is a small bug…

December 1, 2014

WP SUPER CACHE is one of the most used WordPress plugin for cache, but probably there is a small bug in WP Super Cache homepage refresh configuration. This can explain why so many times I received alerts from clients that can’t find their posts in homepage! So I’ve found/modified/made this few lines of code to force refresh of the homepage. You can simply made a cronjob that calls a php file that remove index.* files from super cache directory, or you can write a wordpress action called with wp cron and delete hourly the same files.

Be sure that the directory of your cache is /wp-content/cache/supercache/www.yourdomain.com:

add_action('init','delete_home_cache_hourly');
add_action('delete_home_cache_hourly_job','delete_home_cache_hourly_function');
function delete_home_cache_hourly_function(){
	$dir = $_SERVER['DOCUMENT_ROOT']."/wp-content/cache/supercache/".$_SERVER['HTTP_HOST']."/";
	$file = "index.html";
	unlink($dir.$file);
	unlink($dir.$file.".gz");
}
function delete_home_cache_hourly(){
	if(!wp_next_scheduled('delete_home_cache_hourly_job'))
		wp_schedule_event (time(), 'hourly', 'delete_home_cache_hourly_job');
}

Author

I'm a software engineer, an everyday web developer and a maker. I usually build sites with PHP, within or without WordPress. I build Internet of Things with Arduino and ESP8266. I'm the founder of Rockit.it and Dailybest.it and I'm actually the Chief Technical Officer of Better Days web agency.

Recommended

W3tc plugin feed problem

When your WordPress site has a great number of requests it could happen that your server can’t handle all the…

October 22, 2012

WordPress Fatal error: Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0

How I've beat the php mysterious fatal error unknown in Wordpress caused by caching plugin WP Fastest Cache

November 7, 2019

How to add rel=”nofollow” to links with preg_replace()

Adding rel="nofollow" to external link is a good SEO practice.

September 22, 2015

Social buttons: the fastest way for WordPress, without plugins

NOTE: the code in this post is written for WordPress but you can easily translate it in any language. You’re here…

September 15, 2015

Optimize WordPress, a long list of tips

In the above image you can see your WordPress before reading this post, and after the optimizations you will make…

Limit the number of categories for posts in WordPress

CHOOSE ONLY ONE CATEGORY WORDPRESS If you need to limit the number of categories used by the authors of your…

September 14, 2015