Why do WordPress adds the id=”handle-{js|css}” attribute to scripts and stylesheet?

The id attribute was added to the <style> tags in WordPress v4.1 (2014) — see the Trac changesets 29956 and 29958 which both mentioned ticket #30032 (“Add ID attribute to style element from wp_add_inline_style()“): In order to support partial preview refreshes (#27355), it is important for all partials being updated to have an element with … Read more

How to enqueue js script after another specific js script?

That’s part of the default functionality available in wp_enqueue_script/wp_register_script. The third argument, as seen in the official documentation of enqueue/register script, https://developer.wordpress.org/reference/functions/wp_enqueue_script/, https://developer.wordpress.org/reference/functions/wp_register_script/, is the dependencies array. $deps string[] Optional An array of registered script handles this script depends on. Default: array() So lets say you have script with the handle “sliderjs”, using your code … Read more

Trying to use wp_register_script/style and enqueu them from an array – getting an error [duplicate]

As the “Error Message” (which is in fact a “doing it wrong”-message) is telling you, you’re using the wrong hook: Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Just read about hooks, wrap your code in a callback and then register it properly on one of the … Read more