How to automatically version WordPress assets using their last modified time

Versioning your assets in WordPress is relatively straight-forward as the wp_register_script() and wp_register_style() functions both offer support for specifying a version as a function parameter.

It's easy to use because you simply pass it a value but it's also simple to forget which could result in site visitors loading up stale versions of CSS and JS from a cache.

Thankfully, PHP provides us with an easy method of ensuring the version parameter changes whenever the file changes.

One last thing…

If you liked this article, I'd be incredibly grateful if you tweeted about it.

Also, I don't send emails often but when I do, I try to fill them full of useful goodies. If you like code snippets & dev tips, join my mailing list. There's no catch but I'll probably want to tell you about any new plugins & tools I build.