wp_enqueue_scripts to add jquery and other libraries. But now I wanna add a
<script>alert('hello');</script> before a certain library loads, how could i achieve that?
$deps parameter which exactly does what you need.
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer )
Let's say that your custom code is in a file named
custom.js which is enqueued with a handle
my-custom and you want this to be loded before
my-script1 which is en-queued with a handle.
wp_enqueue_script( 'my-custom', '/path/to/customjs', array() ); wp_enqueue_script( 'my-script1', '/path/to/script1js', array('my-custom') );
The above code says that
my-custom is a dependency for