My little experience with the queue of scripts
– Sometimes you might be surprised, that WordPress/eventually a plugin (from
an unknown reason) enqueued jQuery (not speaking about administration but public
template!). De-queuing is simple: Call
wp_deregister_script('jquery');
before wp_head();
is
run, where the scripts are usually printed out from the queue.
- I think it's good time to stop inserting
<script>
tags into templates directly. As I found out, the queuing principle is quite useful. Especially thanks to the- dependency principle: that will care about all that cases, where the order of scripts' including is important (jQuery first, Thickbox only after)
- the version check:
causes that the newest queued script is included (let's say one plugin enqueues jQuery 1.3 and other 1.2.1 – the newer will be used automatically).well, it's just to be sure the the updated script will be downloaded to client, and won't be used the cached version.
- loading own modification of script and not the version distributed with WP
wp_deregister_script('thickbox'); // unload the possible attempts of loading default thickbox
wp_enqueue_script('thickbox_my', get_bloginfo('template_url') . '/scripts/tb.js', 'jquery', '3.1' ); // just can't load own thickbox and use the 'thickbox' handle
But I'm still not sure this method of inclusion is so much useful in case of
style sheets. Here I will stay by static <link>
insertion,
for now.
See also: Codex/Function Reference/wp_enqueue_script
Update: sorry about the mystification with „auto-choosing the newer version“. I don't know why I believed that WP behaves so.
Comments
Comments are closed.
I quit working with WordPress, comments are closed. My plugins will not be updated any more – at least not by me. Feel free to modify my source codes though… Also I am not able to provide support, sorry. –Kahi