I was just setting up scripts in new theme on development stack. Highly useful tutorial on topic by scribu.
Current version:
PHP Code:
add_action('init', 'restatement_jquery_register');
add_action('wp_footer', 'restatement_footer_scripts');
function restatement_jquery_register() {
if (!is_admin()){
wp_deregister_script('jquery');
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"), false, '1.4.2',true);
}
}
function restatement_footer_scripts() {
if (!is_admin()){
$js='/js/restatement.js';
wp_register_script('restatement', get_stylesheet_directory_uri().$js,array('jquery'),filemtime(STYLESHEETPATH.$js),true);
wp_print_scripts('restatement');
}
}
In init hook I change jquery definition from WP-bundled to Google CDN. Also last parameter tells it to load jquery in the footer, unless other script demands it earlier.
In footer I enqueue my theme's script (or more), version it with file modification time and set dependency on jquery. Since I output it explicitly I can also override this somewhere in the page if needed (regular way enqueues scripts much earlier).
Result in footer:
Code:
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js?ver=1.4.2'></script>
<script type='text/javascript' src='http://localhost/wordpress/wp-content/themes/restatement/js/restatement.js?ver=1266935793'></script>
Only thing I hadn't figured out is how to prevent WP from putting version tag on jquery from Google - it is harmful in that case.
PS might also need to tweak priority on hooking jquery register so it is fired early enough