tripl3inf
4/12/2014 - 9:01 PM

WordPress Asset Management

WordPress Asset Management

// deregister jquery and include from google CDN with bower managed fallback
$url = 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'; // the URL to check against
$test_url = @fopen($url,'r'); // test parameters
if($test_url !== false) { // test if the URL exists
	function load_external_jQuery() { // load external file
		wp_deregister_script( 'jquery' ); // deregisters the default WordPress jQuery
		wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'); // register the external file
		wp_enqueue_script('jquery'); // enqueue the external file
	}
	add_action('wp_enqueue_scripts', 'load_external_jQuery'); // initiate the function
} else {
	function load_local_jQuery() {
		wp_deregister_script('jquery'); // deregisters the default WordPress jQuery
		wp_register_script('jquery', get_stylesheet_directory_uri().'/common/js/vender/bower/jquery/dist/jquery.min.js', __FILE__, false, '1.11.0', true); // register the local file
		wp_enqueue_script('jquery'); // enqueue the local file
	}
	add_action('wp_enqueue_scripts', 'load_local_jQuery'); // initiate the function
}

add_action('wp_enqueue_scripts', 'load_local_jQuery'); // initiate the function
}