Title: [Plugin: Use Google Libraries] Beginner&#039;s problem
Last modified: August 20, 2016

---

# [Plugin: Use Google Libraries] Beginner's problem

 *  Resolved [serons](https://wordpress.org/support/users/serons/)
 * (@serons)
 * [14 years ago](https://wordpress.org/support/topic/plugin-use-google-libraries-beginners-problem/)
 * I have the following in functions.php
 *     ```
       function my_scripts() {
       	wp_deregister_script( 'jquery' );
       	wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js', null, null, true );
       	wp_enqueue_script( 'jquery' );
   
       	wp_deregister_script( 'script_1' );
       	wp_register_script( 'script_1', get_template_directory_uri() . '/js/script_1.js', array( 'jquery' ), null, true );
       	wp_enqueue_script( 'script_1' );
       }
       add_action( 'wp_enqueue_scripts', 'my_scripts' );
       ```
   
 * If UGL is enabled I get
 *     ```
       <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
       <script type="text/javascript">try{jQuery.noConflict();}catch(e){};</script>
       <script type="text/javascript" src="http://wp.dev/sitename/wp-content/themes/themename/js/script_1.js"></script>
       ```
   
 * and the error
 *     ```
       Uncaught exception: TypeError: '$' is not a function
       Error thrown at line 7, column 0 in http://wp.dev/sitename/wp-content/themes/themename/js/script_1.js:
           $(function() {
       ```
   
 * If UGL is not enabled the line `<script type="text/javascript">try{jQuery.noConflict();}
   catch(e){};</script>` is not generated and no errors are generated.
 * From the last question in the FAQ I expect it to work in both cases. Why doesn’t
   it?
 * [http://wordpress.org/extend/plugins/use-google-libraries/](http://wordpress.org/extend/plugins/use-google-libraries/)

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

 *  Plugin Author [Jason Penney](https://wordpress.org/support/users/jczorkmid/)
 * (@jczorkmid)
 * [14 years ago](https://wordpress.org/support/topic/plugin-use-google-libraries-beginners-problem/#post-2788699)
 * When you did this:
 *     ```
       wp_deregister_script( 'jquery' );
       	wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js', null, null, true );
       	wp_enqueue_script( 'jquery' );
       ```
   
 * you broke compatability with how WordPress uses jQuery. Please don’t do this.
   You de-registered the stock jQuery, then re-registered an unsupported version,
   without all it’s metadata present that core WordPress expects to function, and
   you told it to load in the footer, which is totally unsupported.
 * By a fluke, when UGL was enable it restored some of that core functionality, 
   which gives you the error (which is what you would get if you had used core WordPress
   without messing it up as well).
 * Change your function to this:
 *     ```
       function my_scripts() {
       	wp_register_script( 'script_1', get_template_directory_uri() . '/js/script_1.js', array( 'jquery' ), null, true );
       	wp_enqueue_script( 'script_1' );
       }
       add_action( 'wp_enqueue_scripts', 'my_scripts' );
       ```
   
 * And get your script working without UGL enabled, then enable UGL and it should
   still work.
 * I’d guess you aren’t writing your script to be compatable with jQuery’s noConflict
   mode, and jQuery in WordPress (with or without UGL) is in noConflict mode.
 * Short version: Don’t just use `$` you have to use `jQuery`. For more details 
   see the jQuery docs.
 *  Thread Starter [serons](https://wordpress.org/support/users/serons/)
 * (@serons)
 * [14 years ago](https://wordpress.org/support/topic/plugin-use-google-libraries-beginners-problem/#post-2788722)
 * Thank you for your answer. My question is a reflection of my (now slightly lower)
   ignorance. I still get the try/catch line when UGL is enabled but errors are 
   gone.
 * > Don’t just use $ you have to use jQuery. For more details see the jQuery docs
 * Thank you. I did a mindless s/\$\(/jQuery(/ and it seemed to have fixed complaints
   about $(). For reference the following page was useful, which also links to jQuery’s
   docs: [http://codex.wordpress.org/Function_Reference/wp_enqueue_script](http://codex.wordpress.org/Function_Reference/wp_enqueue_script)
 * > You de-registered the stock jQuery, then re-registered an unsupported version
 * What do you mean by unsupported?
 *  Plugin Author [Jason Penney](https://wordpress.org/support/users/jczorkmid/)
 * (@jczorkmid)
 * [14 years ago](https://wordpress.org/support/topic/plugin-use-google-libraries-beginners-problem/#post-2788737)
 * > I still get the try/catch line when UGL is enabled but errors are gone.
 * As you should, because…
 * > What do you mean by unsupported?
 * Firstly, the version of jQuery shipped with WordPress is modified, so it does
   not match what is on googles servers (the try/catch injection essentially makes
   them match up). Secondly, you aren’t registering an exact version, and WordPress
   requires an exact version (also when you ask for 1.7 from google, vs 1.7.x, google
   sends a short time cache header, since the file is likely to change). You are
   also not registering it with all the same options as stock WordPress, so other
   parts of WordPress may break. And the stock registration may include extra data
   not included in the register call, and this can cause additional problems. UGL
   handles all this so you don’t have to 🙂

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

The topic ‘[Plugin: Use Google Libraries] Beginner's problem’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/use-google-libraries.svg)
 * [Use Google Libraries](https://wordpress.org/plugins/use-google-libraries/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/use-google-libraries/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/use-google-libraries/)
 * [Active Topics](https://wordpress.org/support/plugin/use-google-libraries/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/use-google-libraries/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/use-google-libraries/reviews/)

## Tags

 * [script](https://wordpress.org/support/topic-tag/script/)

 * 3 replies
 * 2 participants
 * Last reply from: [Jason Penney](https://wordpress.org/support/users/jczorkmid/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/plugin-use-google-libraries-beginners-problem/#post-2788737)
 * Status: resolved