Title: Google Ajax jQuery wp_enqueue_script on plugin not working
Last modified: August 30, 2016

---

# Google Ajax jQuery wp_enqueue_script on plugin not working

 *  [cgaybba](https://wordpress.org/support/users/cgaybba/)
 * (@cgaybba)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/google-ajax-jquery-wp_enqueue_script-on-plugin/)
 * I have written a custom plugin that should ‘enqueue’ a few .js files into WordPress.
   The plugin is basically a jQuery Autocomplete that gets the information from 
   a .js file and inject it into Gravity Form input field using CSS class.
 * I got it all to work, but I have a problem with the “enqueue” of Google’s ajax
   jQuery file. If I enqueue it in a certain way, the form works 100%, but than 
   it screws around with the admin, especially the “add media” button and the “Visual/
   Text” toggle buttons on the page.
 * I’ve tried the “if (!is_admin())” enqueue scripts, but than the form doesn’t 
   work as it should.
 * So basically, this works, but screws with admin:
    `wp_enqueue_script('jquery-
   custom-injection', 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.
   min.js', __FILE__, '2.1.3', 0 );`
 * This is how it should be, but it doesn’t work:
 *     ```
       //Making jQuery Google API
       function modify_jquery() {
           if (!is_admin()) {
               wp_deregister_script('jquery');
               wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js', false, '2.1.3');
               wp_enqueue_script('jquery');
           }
       }
       add_action('init', 'modify_jquery');
       ```
   
 * My plugin’s main file looks like this:
 *     ```
       // registering core Javascript files
       wp_enqueue_script('airport-codes-styles', plugins_url('/css/airports.css', __FILE__), '1.0.0', true );
       wp_enqueue_script('jquery-custom-injection', 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js', __FILE__, '2.1.3', 0 );
       wp_enqueue_script('airport-codes', plugins_url('/js/airports.js', __FILE__), '1.0.0', 1 );
       wp_enqueue_script('airport-autocomplete-method', plugins_url('/js/method.js', __FILE__), '1.0.0', 1 );
       wp_enqueue_script('jquery-autocomplete', plugins_url('/js/jquery.autocomplete.js', __FILE__), '1.0.0', 1 );
       ```
   
 * This is my first time using a plugin to inject Java files, so I am fairly a noob.

Viewing 1 replies (of 1 total)

 *  Thread Starter [cgaybba](https://wordpress.org/support/users/cgaybba/)
 * (@cgaybba)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/google-ajax-jquery-wp_enqueue_script-on-plugin/#post-6282160)
 * After looking around I came upon the following and it seems to sort out my problem:
 *     ```
       if (!is_admin()) {
       wp_enqueue_script('jquery-custom-injection', 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js', __FILE__, '2.1.3', 0 );
       };
       ```
   
 * Is this the correct way to do this?
 * Plugin file:
 *     ```
       // enqueue Google Ajax jQuery file only on front-end and not in wp-admin
       if (!is_admin()) {
       wp_enqueue_script('jquery-custom-injection', 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js', __FILE__, '2.1.3', 0 );
       };
   
       // registering core Javascript files
       wp_enqueue_script('airport-codes-styles', plugins_url('/css/airports.css', __FILE__), '1.0.0', true );
       wp_enqueue_script('airport-codes', plugins_url('/js/airports.js', __FILE__), '1.0.0', 1 );
       wp_enqueue_script('airport-autocomplete-method', plugins_url('/js/method.js', __FILE__), '1.0.0', 1 );
       wp_enqueue_script('jquery-autocomplete', plugins_url('/js/jquery.autocomplete.js', __FILE__), '1.0.0', 1 );
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Google Ajax jQuery wp_enqueue_script on plugin not working’ is closed
to new replies.

## Tags

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

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 1 participant
 * Last reply from: [cgaybba](https://wordpress.org/support/users/cgaybba/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/google-ajax-jquery-wp_enqueue_script-on-plugin/#post-6282160)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
