Packages for manipulating assets in WordPress
You know how limited wp_enqueue_script
and wp_enqueue_style
are if you want to do anything else than just adding them to the page? If you want to load a script asynchronously or defer it (and its dependents), or basically add any additional attribute, you’ll have to manipulate the HTML string.
Many years ago, there was gmazzap/Occipital —which got deprecated and eventually superseded by Brain-WP/Assets —if you wanted to manipulate assets in WordPress. I wrote a package I have used in many projects meanwhile to achieve a similar result. Deferring scripts and their dependents, inlining JS and CSS, adding translations and all of this on a fluid interface. Check the asset handling on a community website we built for the WordPress Berlin Tech Meetups a few years ago; and the fluid scripts and styles, respectively. The package has evolved since, but I’ve never written any documentation for it, unfortunately.
Mark Jaquith has recently announced a new package: Encute! It looks really promising, has documentation and a UI for code-generation is around the corner.