When assets are loaded, the raw get_stylesheet() directory name is "cleaned up" and the version is stripped off:
|
$handle = preg_replace('/-\d+(_\d+)*$/', '', get_stylesheet()); |
This might have seemed convenient at the time, but it's introduced a very subtle difference between production and dev builds which make assets difficult to enqueue or dequeue. Basically if we don't remember to munge the get_stylesheet name, asset enqueueing will fail on production.
Example
We are enqueueing and dequeueing styles during a theme transition in a theme named iop-theme. The following code works locally (where theme directories do not yet have version numbers attached) but fails in production where the versioned theme lives in a directory like top-theme-1_5_12:
$themeSlug = get_stylesheet();
wp_enqueue_style("{$themeSlug}-legacy"); // ensure the legacy stylesheet is loaded (for now)
wp_dequeue_style("{$themeSlug}-main"); // remove the main stylesheet until we're ready to switch
To make that work, the theme needs to re-munge get_stylesheet to match the wp-theme-init munged asset handles like this:
$themeSlug = preg_replace('/-\d+(_\d+)*$/', '', get_stylesheet());
yuck. no. undo.
When assets are loaded, the raw
get_stylesheet()directory name is "cleaned up" and the version is stripped off:wp-theme-init/src/ThemeInit/Manifest.php
Line 129 in 768cfd4
This might have seemed convenient at the time, but it's introduced a very subtle difference between production and dev builds which make assets difficult to enqueue or dequeue. Basically if we don't remember to munge the
get_stylesheetname, asset enqueueing will fail on production.Example
We are enqueueing and dequeueing styles during a theme transition in a theme named
iop-theme. The following code works locally (where theme directories do not yet have version numbers attached) but fails in production where the versioned theme lives in a directory liketop-theme-1_5_12:To make that work, the theme needs to re-munge
get_stylesheetto match the wp-theme-init munged asset handles like this:yuck. no. undo.