Google Ajax jQuery wp_enqueue_script on plugin not working
-
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.
- The topic ‘Google Ajax jQuery wp_enqueue_script on plugin not working’ is closed to new replies.