Title: Plugin scripts are loaded before jQuery
Last modified: March 15, 2019

---

# Plugin scripts are loaded before jQuery

 *  Resolved [ChrisHPZ](https://wordpress.org/support/users/chrishpz/)
 * (@chrishpz)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/plugin-scripts-are-loaded-before-jquery/)
 * Hi 10Web, potential bug report here. In QA’ing a site , I noticed a console error
   that jQuery isn’t defined. The cause of this error is from the Photo Gallery 
   plugin inserting javascript right after the <title> tag. At this point, jQuery
   isn’t loaded yet. I enabled the option to “only load photo gallery scripts” on
   pages where a photo gallery is needed, but this didn’t change anything. We don’t
   have anything that would cause this. Offending code below:
 *     ```
       <script>
             var bwg_admin_ajax = 'https://anterra.com/wp-admin/admin-ajax.php?action=shortcode_bwg';
             var bwg_ajax_url = 'https://anterra.com/wp-admin/admin-ajax.php?action';
             var bwg_plugin_url = 'https://anterra.com/wp-content/plugins/photo-gallery';
             jQuery(document).ready(function () {
               bwg_check_ready = function () {}
               jQuery(document).keyup(function(e) {
                 if ( e.keyCode == 27 ) {
                   bwg_remove_loading_block();
                 }
               });
             });
             // Set shortcode popup dimensions.
             function bwg_set_shortcode_popup_dimensions() {
               var H = jQuery(window).height(), W = jQuery(window).width();
               jQuery("#TB_title").hide().first().show();
               // New
               var tbWindow = jQuery('#TB_window');
               if (tbWindow.size()) {
                 tbWindow.width(W).height(H);
                 jQuery('#TB_iframeContent').width(W).height(H);
                 tbWindow.attr('style',
                   'top:'+ '0px !important;' +
                   'left:' + '0px !important;' +
                   'margin-left:' + '0;' +
                   'z-index:' + '1000500;' +
                   'max-width:' + 'none;' +
                   'max-height:' + 'none;' +
                   '-moz-transform:' + 'none;' +
                   '-webkit-transform:' + 'none'
                 );
               }
               // Edit
               var tbWindow = jQuery('.mce-window[aria-label="Photo Gallery"]');
               if (tbWindow.length) {
                 // To prevent wp centering window with old sizes.
                 setTimeout(function() {
                   tbWindow.width(W).height(H);
                   tbWindow.css({'top': 0, 'left': 0, 'margin-left': '0', 'z-index': '1000500'});
                   tbWindow.find('.mce-window-body').width(W).height(H);
                 }, 10);
               }
             }
             // Create loading block.
             function bwg_create_loading_block() {
               jQuery('body').append('<div class="loading_div" style="display:block; width: 100%; height: 100%; opacity: 0.6; position: fixed; background-color: #000000; background-image: url('+ bwg_plugin_url +'/images/spinner.gif); background-position: center; background-repeat: no-repeat; background-size: 50px; z-index: 1001000; top: 0; left: 0;"></div>');
             }
             // Remove loading block.
             function bwg_remove_loading_block() {
               jQuery(".loading_div", window.parent.document).remove();
               jQuery('.loading_div').remove();
             }
       	  </script>
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fplugin-scripts-are-loaded-before-jquery%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Support [Kima Baghdasaryan](https://wordpress.org/support/users/kimabaghdasaryan/)
 * (@kimabaghdasaryan)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/plugin-scripts-are-loaded-before-jquery/#post-11320736)
 * Hi,
 * Please note that we have written the code according to WordPress Standart format.
 * This problem might be a conflict with another plugin on your website.
 * Please try to deactivate the rest of your plugins and check whether the problem
   persists.
    Also, if possible, please temporarily switch the theme of your website
   and see if the issue occurs.
 * You can re-activate the plugins and change the theme back again after troubleshooting.
   
   Please inform us of the results.
 * Cheers!
 *  Thread Starter [ChrisHPZ](https://wordpress.org/support/users/chrishpz/)
 * (@chrishpz)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/plugin-scripts-are-loaded-before-jquery/#post-11332451)
 * I did as instructed and deactivated plugins and switched to a default WordPress
   theme. The issue still persisted. I took a look at the plugin code. So the function
   responsible for adding the above code is coming from public function global_script()
   on line 963 in photo-gallery.php. Obviously, this function relies on jQuery. 
   So it has to load after jQuery is loaded.
 * Now if we check out line 161 in the same file, we see the following:
 * `add_action('admin_head', array($this, 'global_script'));`
 * What’s missing here is a reliance on jQuery. The same thing applies to the function
   on line 1862 in photo-gallery.php
 *  Plugin Support [Kima Baghdasaryan](https://wordpress.org/support/users/kimabaghdasaryan/)
 * (@kimabaghdasaryan)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/plugin-scripts-are-loaded-before-jquery/#post-11334099)
 * Hi,
 * We are still in the same opinion, that you have a conflict, jQuery loads late.
   However, we will write poor Javascript in order to solve this issue.
 * Thank you!
 * Have a nice day!
 *  Thread Starter [ChrisHPZ](https://wordpress.org/support/users/chrishpz/)
 * (@chrishpz)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/plugin-scripts-are-loaded-before-jquery/#post-11339537)
 * How could I possibly have a conflict when I use a default WordPress theme and
   only Photo Gallery plugin enabled? The global script function still loads its
   output directly after the <title></title> tags on the front end of the site.
 *  [ausdamo](https://wordpress.org/support/users/ausdamo/)
 * (@ausdamo)
 * [7 years ago](https://wordpress.org/support/topic/plugin-scripts-are-loaded-before-jquery/#post-11341766)
 * We are experiencing the same issue with version 1.5.19.
 * Uncaught TypeError: jQuery(…).hideShow is not a function
 * jQuery isn’t available at the time the script is being called.
 *  Plugin Support [Kima Baghdasaryan](https://wordpress.org/support/users/kimabaghdasaryan/)
 * (@kimabaghdasaryan)
 * [7 years ago](https://wordpress.org/support/topic/plugin-scripts-are-loaded-before-jquery/#post-11342201)
 * Hi,
 * As we have written above, we will write poor Javascript in our future updates
   of the Photo Gallery Plugin in order to solve this issue.
 * Thank you for your understanding!
 * Have a nice day!

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

The topic ‘Plugin scripts are loaded before jQuery’ is closed to new replies.

 * ![](https://ps.w.org/photo-gallery/assets/icon-256x256.png?rev=2068745)
 * [Photo Gallery by 10Web - Mobile-Friendly Image Gallery](https://wordpress.org/plugins/photo-gallery/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/photo-gallery/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/photo-gallery/)
 * [Active Topics](https://wordpress.org/support/plugin/photo-gallery/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/photo-gallery/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/photo-gallery/reviews/)

## Tags

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

 * 6 replies
 * 3 participants
 * Last reply from: [Kima Baghdasaryan](https://wordpress.org/support/users/kimabaghdasaryan/)
 * Last activity: [7 years ago](https://wordpress.org/support/topic/plugin-scripts-are-loaded-before-jquery/#post-11342201)
 * Status: resolved