Title: rewrite jquery insertion functions script
Last modified: August 19, 2016

---

# rewrite jquery insertion functions script

 *  [micasuh](https://wordpress.org/support/users/micasuh/)
 * (@micasuh)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/rewrite-jquery-insertion-functions-script/)
 * Paul Irish wrote a new version of jquery insertion into the [[HTML5 Boilerplate](http://html5boilerplate.com/)
   project that looks like this:
 *     ```
       <script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
           <script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.4.2.js"%3E%3C/script%3E'))</script>
       ```
   
 * Here’s Paul’s explanation: [http://paulirish.com/2010/the-protocol-relative-url/](http://paulirish.com/2010/the-protocol-relative-url/)
 * I’m very interested to port this over verbatim for WordPress projects using the
   wp_enqueue_script.
 *     ```
       function add_jquery_script() {
             wp_deregister_script( 'jquery' ); // get rid of WP's jQuery
             wp_register_script( 'jquery_cdn', '//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js', array(), '1.0', true );
             wp_enqueue_script( 'jquery_cdn' );
             echo'<script>!window.jQuery && document.write(unescape(\'%3Cscript src="' . get_bloginfo('template_directory') . '/js/libs/jquery-1.4.2.min.js"%3E%3C/script%3E\'))</script>';
               }
       ```
   
 * Two main problems:
    1. First register script line spits out absolute path rather than relative. The
       double-forward slashes should not have WordPress’ URI preceding the link.
    2. The echo forces the code in at the top (because it likely doesn’t belong in 
       this function in this way).
 * It’d be cool to get both of these versions working with the wp_enqueue_script
   but I realize it’s likely not possible.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [micasuh](https://wordpress.org/support/users/micasuh/)
 * (@micasuh)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/rewrite-jquery-insertion-functions-script/#post-1743914)
 * I hope someone sees this who knows the answer b/c I’d love to implement this 
   in my projects.
 *  [jmh](https://wordpress.org/support/users/jmh/)
 * (@jmh)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/rewrite-jquery-insertion-functions-script/#post-1743950)
 * Hey, I’ve been wondering this same thing. I found this blog post and used his
   idea for problem number 1:
 * [http://beneverard.co.uk/blog/wordpress-loading-jquery-correctly](http://beneverard.co.uk/blog/wordpress-loading-jquery-correctly)
 * I am still searching for the solution to providing a local fallback using the
   proper wp_enqueue_script function

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘rewrite jquery insertion functions script’ is closed to new replies.

## Tags

 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [wp_enqueue_script](https://wordpress.org/support/topic-tag/wp_enqueue_script/)
 * [wp_register_script](https://wordpress.org/support/topic-tag/wp_register_script/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [jmh](https://wordpress.org/support/users/jmh/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/rewrite-jquery-insertion-functions-script/#post-1743950)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
