php - Load jQuery from Google AJAX Libraries API in Wordpress with "fallback script" -
i have added wordpress function load jquery library google hosted libraries
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11); function my_jquery_enqueue() { wp_deregister_script('jquery'); wp_register_script('jquery', "http" . ($_server['server_port'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js", false, null); wp_enqueue_script('jquery'); }
it create this
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
how can include fallback option, per html5boilerplate suggested
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script>window.jquery || document.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
like this
try this. replace code code. handle all.
/************* enqueue js *************************/ /* pull jquery google's cdn. if it's not available, grab local copy. */ $url = 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'; // url check against $test_url = @fopen($url,'r'); // test parameters if( $test_url !== false ) { // test if url exists function load_external_jquery() { // load external file wp_deregister_script( 'jquery' ); // deregisters default wordpress jquery wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'); // register external file wp_enqueue_script('jquery'); // enqueue external file } add_action('wp_enqueue_scripts', 'load_external_jquery'); // initiate function } else { function load_local_jquery() { wp_deregister_script('jquery'); // initiate function wp_register_script('jquery', get_template_directory_uri().'/js/jquery.js', __file__, false, '1.7.2', true); // register local file wp_enqueue_script('jquery'); // enqueue local file } add_action('wp_enqueue_scripts', 'load_local_jquery'); // initiate function }
put code in functions.php
Comments
Post a Comment