codewithfeeling
codewithfeeling

Reputation: 6576

Gravity forms AJAX not working with WordPress Roots/Sage theme

When trying to use AJAX with Gravity Forms 1.9.9 and the Sage WordPress theme, there is the dreaded Uncaught ReferenceError: jQuery is not defined error and AJAX does not work. How can this be resolved?

Upvotes: 0

Views: 2345

Answers (1)

codewithfeeling
codewithfeeling

Reputation: 6576

If you are using the Sage theme for WordPress, jQuery is registered to load in the footer. Gravity Forms requires that jQuery is loaded in the header, so you just need to make a small change to make sure this happens.

These instructions are for the Sage theme, version 8.2.1

Open [your_theme_name]/lib/assets.php, go to line 112 (or locate wp_register_script('jquery'... ).

Simply change the final true (which specifies that the script should load in the footer to false - it should finish up like this:

wp_register_script('jquery', bower_map_to_cdn(array(
  'name' => 'jquery',
  'cdn' => 'google',
  'file' => 'jquery.min.js'
), asset_path('scripts/jquery.js')), [], null, false);

then jQuery will load in the head and your AJAX should fire up as intended.

Upvotes: 1

Related Questions