How Can I Change Order Of Scripts In Head In Wordpress?
I need jquery.js would be first in the head then colorbox.js then my custom-script.js. My custom script depends on jquery and colorbox. But it always higher in the head of page the
Solution 1:
You should include the script with wp_enqueue_script
and add jQuery as a dependency, that way wordpress takes care of the order
<?php
wp_enqueue_script( $handle, $src, $dependency, $ver, $in_footer );
?>
so something like :
wp_register_script( 'colorbox', plugins_url('/path/colorbox.js', __FILE__), array( 'jquery' ), false, true );
wp_enqueue_script( 'colorbox' );
wp_register_script( 'custom', plugins_url('/path/custom-script.js', __FILE__), array( 'jquery', 'colorbox' ), false, true );
wp_enqueue_script( 'custom' );
Post a Comment for "How Can I Change Order Of Scripts In Head In Wordpress?"