Keeping dynamic header images with WP Super Cache
The WP Super Cache plugin comes highly recommended, especially with the theme that I’m using for my blog layout. I specifically chose this layout with the intention of caching (because of its high load times), but wanted to keep the dynamic header image.
There are many ways of going about doing the random image selection. I am retrieving an image based on the images stored in a particular directory. I used this regex:
if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) {
$images[] = $img_file;
}
to retrieve my images, and
$image = file_get_contents($root . $path . “/” . $img);
to retrieve the actual image. Now WP Super Cache can still serve up a cached page with http://nathanielengelsen.com/headerimage.php always set as the default header image, but headerimage.php can serve up a random dynamic image with every call.
