I am trying to load jQuery from the Google cdn with a local jQuery fallback, while also loading an additional script file for my own js. My questions are:
— How would I load the local fallback file in case the Google cdn fails, in addition to the following code?
— Is the following code efficient and well written?
— And finally, how would I load multiple script files (like how the theme.js file is being loaded)?
Thanks in advance!
– j
/* Add jQuery as a dependency */
function my_scripts_method() { // Better than init hook
wp_deregister_script(‘jquery’); // Remove the inbuilt jquery
wp_register_script(‘jquery’, ‘http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js’, false, ‘1.3.2’, true); // Include the google cdn jQuery
wp_enqueue_script(‘jquery’); // Load jQuery
// Load a JS file from my theme: js/theme.js
wp_enqueue_script(
‘my_script’, // Name of the script
get_bloginfo(‘template_url’) . ‘/js/theme.js’, // Location
array(‘jquery’), //Dependencies
‘1.0’, // Script version
true); // Load in footer.( wp_footer() must be present!)
}
add_action(‘wp_enqueue_scripts’, ‘my_scripts_method’);