Support » Theme: Boilerplate » Deregistering Jquery doesnt account for enqueued dependencies cause double load

  • After reading the support ticket here, I found I was experiencing the same issue. I had narrowed the plugin down to specifically Bannerspace and Contact Form 7, and discovered the reason this is occuring, though I don’t know the solution.

    It is true the theme deregisters the enqueued jquery script, the problem is that this doesn’t account for scripts that include jquery as a dependent script. So for example in contact form 7 view the following line of code.

    file: contact-form-7/includes/controller.php line 196

    wp_enqueue_script( 'contact-form-7',
    		wpcf7_plugin_url( 'includes/js/scripts.js' ),
    		array( 'jquery', 'jquery-form' ), WPCF7_VERSION, $in_footer );

    Even though jquery has been deregistered, when wp sees that it is a dependent script in the enqueued contact-form-7 it re-enqueues jquery to be added. Thus we get both WP core’s version and H5BP’s version.

    I have resolved this in Bannerspace by writing a plugin that deregisters the bannerspace actions, and then adds it scripts back in without the dependency. I am working on doing the same for contact-form-7, but its a pain to have to do this for any plugin that has this issue. Especially when declaring jquery as dependency is considered good practice, and many plugins will likely continue doing it.


Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi


    Forum Moderator

    It is true the theme deregisters the enqueued jquery script

    Can you elaborate on this? I’ve just quickly scanned the theme and I couldn’t see where it is deregistering core jQuery. If this is the case, then it is the theme that is at fault. No theme should ever deregister core jQuery.

    in theme file theme/boilerplate/boilerplate-admin/admin-menu.php line 479

    //	$options['H5BP_jquery_js']
    		if ( ! function_exists( 'H5BP_add_jquery_script' ) ):
    			function H5BP_add_jquery_script() {
    				$cache = H5BP_cache_buster();
    				$options = get_option('plugin_options');
    				$version = ($options['H5BP_jquery_version']) ? $options['H5BP_jquery_version'] : '1.10.2';
    				wp_deregister_script( 'jquery' ); // get rid of WP's jQuery
    				echo '<script src="//'.$version.'/jquery.min.js"></script>'.PHP_EOL; // try getting from CDN
    				echo '<script>window.jQuery || document.write(unescape(\'%3Cscript src="' .H5BP_URL. '/js/jquery.js'.$cache.'"%3E%3C/script%3E\'))</script>'.PHP_EOL; // fallback to local if CDN fails
    		endif; // H5BP_add_jquery_script

    It deregisters jquery so that it can add it in at the bottom in the footer.



    Forum Moderator

    Ok – got it! Looks like it’s adding Google’s jQuery instead of core. There isn’t much I can do to help with your current problems but I will bring this up with the theme review team as I’m not 100% sure this is allowable for exactly the reasons you have been citing.



    Forum Moderator

    OK – had a quick chat with a couple of the theme review admins. The consensus is that this theme is DEFINITELY in the wrong. No WPORG hosted theme should be doing this now and shouldn’t have been doing it for the past couple of years. As a result, the theme may now be suspended until the issue is corrected.

    Again, I appreciate that this will not help your situation right now but it will stop others hitting the same problem in future. If the theme’s developer is willing, I am sure that the theme review team as a whole will be only too happy to help him/her in correcting the problem, so that an updated, shiny, now-doing-it-properly, version of Boilerplate will be released asap.

    Theme Author Aaron T. Grogg


    @jevedor: I’m sorry you were having trouble with my Theme, and I really wish you would have simply reached out to me. In fact, my Theme did not force you to do anything with regards to jQuery. You could use your own, WP’s, some other plug-ins, none, whatever you want. By reading the documentation, you would learn that the Theme’s Admin page gave you, the site owner, the option of adding jQuery via the Theme or not. And adding via the Theme offers choices as well, such as adding the scripts at the bottom of the page (keeping with current best-practices) or at the top of the page (in case you have some plug-in that requires that). Additionally, by using the Theme’s version of jQuery, you can have the advantage of trying to use Google’s CDN version. Being distributed means probably faster for your users. Being served from Google’s server means it might be cached in a user’s browser. Being from another domain means the browser can download multiple files at once. And just in case there is a problem getting that Google CDN version, the Theme will use it’s local version as a fallback.

    @esmi: Thanks for making such a rash, executive decision with 0 attempt to be a reasonable person or developer. This action completely epitomizes the kind of behavior WP has exhibited from the moment I started trying to do something to help my developer community. You’ve actually done me a favor, because I was so sick of trying to deal with updates through “the WordProcess”, that my updates had been horribly lagging, and my Theme (and its users) have been suffering. But now, I am free to move beyond the repressive rules, regulations and lockdown of the WP Repo, and simply move my updates to Github.

    So, yeah, I guess that’s that. Thanks again everyone.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Deregistering Jquery doesnt account for enqueued dependencies cause double load’ is closed to new replies.