jQuery Not Moving to Header

This question has been asked and responded to previously such as:
Load JQuery-library in head, conflict with plugin(s)
Soil 3.4 - Force jQuery into the header

However, the solution in both of those cases does not appear to be working for me so wondering if perhaps something has changed since then since one of them is over a year old.

As mentioned by others in those threads, the popular Gravity Forms plugin chokes in Sage (at least with Soil), because jQuery is loaded in the footer and the plugin requires it in the header. To note, I’ve tried toggling the GF setting conflict mode and no conflict mode but didn’t seem to help.

The other posts suggest that Sage by default shouldn’t put jQuery in the footer, and only the soil plugin, in particular the jQuery CDN line does that. And the solution should be either commenting out the jQuery CDN line in assets in setup.php or the better solution is to change “true” to “false” in jquery-cdn.php. I’ve tried commenting out the line in setup and jquery stays in the footer. It simply goes from Google jQuery to regular WP. Tried uncommenting it, and setting it as false and still remains in the footer.

I can’t seem to find any other plugins causing the issue (I have advanced custom fields, facebook comments, jetpack (disabled), wp migrate pro, wp retina 2x, wp-mail-smtp and yoast installed currently.

Ideally, I’d like to leave soil enabled and jQuery should load in the header only on the contact page (which uses Gravity Forms), but currently simply trying to get it to load at the top on all pages isn’t working, so wondering if something has changed with Soil, WP, or Sage, or if something on my end?

Somehow I can spend hours debugging and the moment I finally post a question here, my mind things of a possible solution.

So rather than simply disabling jquery CDN in setup.php, I disabled the whole soil plugin in wordpress admin and then jQuery does move to the top, which helps narrow down the problem.

Then when I went back to setup.php, I noticed another part of soil that I hadn’t seen before: add_theme_support(‘soil-js-to-footer’); Well duh!

So while in the older posts simply disabling jquery cdn was the solution it looks like since then there is now that js to footer line which needs to be commented out instead.

I renabled jquery cdn in setup.php and set it to false in wp_register_script line. I then disabled soil-js-to-footer in assets php and now jquery appears to load in the footer on the homepage and on contact page it loads in the header.

I’ll have to check to see how it’s working on the other pages, but looks like this one is solved. Hopefully it will help others who run into the same issue.

soil-js-to-footer is not enabled in Sage by default: https://github.com/roots/sage/blob/master/lib/setup.php#L13-L17

So someone must have added it to your project.

And yeah, it’s not enabled for issues like this, where plugins (even very large and well known plugins) decide to just dump a bunch of jQuery right in the middle of a page, and hope that jQuery and any depedencies it requires was loaded in the header.

I suppose if they’re loading a JavaScript file in the head with a dependency, then it’s generally a relatively safe assumption. I believe how the Soil js to footer works is it removes the head JS output entirely :joy: