-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dequeue ability #3
Comments
I could also see this being useful for conditional assets. $assets = Assets::forTheme();
// enqueue a whole bunch of assets
foreach($myAssets as $key => $asset) {
$myAssets[$key] = $assets
->enqueueScript($asset, ['jquery'])
->useDefer();
}
// dequeue the not needed one.
if ( ! get_field('fancy-page-intro', 'options) ) {
// ability to pass in the asset object would be nice
$assets->dequeue($myAssets['conditional-asset']);
} |
You might want to check out https://github.com/inpsyde/assets a much more maintained project. I had the exact same dequeue wish there inpsyde/assets#23 but couldn't figure out a sane implementation. |
@mindfullsilence this is implemnted in v0.2.0 - see https://github.com/Brain-WP/Assets/releases/tag/0.2.0. If you are on WP 6.3+ and PHP 8.0+ you can use that. Be mindful there are breaking changes in the internal API, but not much (or not at all) in the consuming API. @lkraav Yes, Inpsyde Assets is more actively maintained (mostly because is much more used), but there are differences with that library:
On the other hand, that library has more things this library has not:
Those are things that require custom code using this lib. |
Tyvm for the update, we'll take a closer look! |
Nice code - not joking when I say it reduced my asset enqeueuing code by >50% and made it far more readable :D
For completeness though, it'd be nice to have a simple method for dequeuing an arbitrary asset. As an example, my theme spits out its own styles for a particular plugin, making the plugin styles useless. It'd be great to be able to dequeue the plugin styles through the class (for literally no other reason than pretty code)
The text was updated successfully, but these errors were encountered: