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

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…

September 15, 2015

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

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

Remove archive pages in WordPress, how to

I think that in most blogs (that is not all) archive pages are redundant content and there’s no need to…

September 8, 2015

WordPress anyone can register, but no email confirmation

Many times it has happened to me that my WordPress installation properly send emails using wp_mail directly, specifing also the…

August 25, 2015