wp-theme-semver-bump

Bumps a Wordpress theme's version number, according to semver rules.

Usage no npm install needed!

<script type="module">
  import wpThemeSemverBump from 'https://cdn.skypack.dev/wp-theme-semver-bump';
</script>

README

WP theme semantic versioning

A small utility that bumps WordPress theme versions using semantic versioning. Useful for cache-busting production sites.

Usage

Terminal

In the theme's folder, run

npx wp-theme-semver-bump

In a script (e.g. gulp)

const bump = require('wp-theme-semver-bump')
// ...
bump()

Arguments

Release type

npx wp-theme-semver-bump minor

or

bump('minor')

Custom file location

npx wp-theme-semver-bump patch relative/path/to/style.css

or

bump('patch', './relative/path/to/style.css')

Why?

The main use case is cache busting in production. No more "Try emptying the cache or opening in an incognito tab"!

The theme version can be appended to enqueued assets:

// functions.php or wherever you enqueue assets

// get the Version value from the theme's root style.css
$theme_version = wp_get_theme()->get('Version'); 

// append the version no. to the asset's src / href, e.g. 'theme/css/style.min.css?ver=0.1.0'
wp_enqueue_style('style', get_stylesheet_directory_uri() . '/css/style.min.css', [], $theme_version);