Workarounds for WordPress 4.9 Template File Caching

cache pallets | cache wp_query

Caching is a devil’s bargain: it makes things faster by showing you old versions of those things. This results in many of the most frustrating debugging experiences of a developer’s life; in my work, if something’s broken, the explanation is caching until proven otherwise—much like the default explanation for loose ends in the Star Wars universe is the Force.

WordPress 4.9 now caches the active theme’s files in an attempt to speed the CMS up generally, and things are breaking. There’s no way to clear this cache by default: it lives in a transient, and unless you know that, and how to clear transients, then you’re stuck waiting up to an hour for changes you make to your theme files to come through.

This is the first time in recent memory that a WordPress version update has added a feature that can reasonably be expected to break things for large numbers of users, without giving users a tool to fix that disruption. That’s sort of disappointing. On the other hand, I suppose it does force people billing themselves as WordPress developers to get a bit more educated, which I’m all for in general.

In the meantime, if you need to clear that cache, there’s a good Reddit thread offering workarounds, a plugin that clears the cache, a plugin that adds a button for clearing the cache yourself, and other solutions. The linked article is code for your theme’s functions.php that clears the transient responsible for the caching on each page load.

Image credit: Sam Beebe

2 Responses


  • Jesse Owens says:

    I’m thinking you could use the wp-cli command wp transient delete for this, any idea if wp cache flush would do the deed as well?

  • Igor Benic says:

    That caching (as per discussion on the ticket) will be removed in 4.9.1 so everything should be fine. It is a weird one since it was not documented anywhere. Another thing I was a bit confused on that approach is that there was no other method of removing/disabling the cache except changing the theme version.

Add a comment