Skip to content

Stop stripping versions from Manifest asset handles #57

Description

@joemaller

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions