1

I placed the following script in my functions file to deregister Wordpress jquery and use the Google CDN.

// use the Google hosted jquery library
if (!function_exists('modify_jquery')) {
    function modify_jquery() {
        if (!is_admin()) {
            wp_deregister_script('jquery');
            wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js', false, '1.11.3', true);

            wp_enqueue_script('jquery');
        }
    }
}
add_action('init', 'modify_jquery');

I'm using Gravity Forms and it looks like on any page that has a form the jquery library is being loaded in the head section. Is this something that Gravity forms is doing? I'm just wondering how it's able to ignore my script in the functions file. I do recall in the past that Gravity form requires jquery to load in the head and not be defered. Is this still true?

  • Honestly, I have had so much trouble with Gravity Forms specifically because of this issue that I switched to Ninja forms. – pwbred Nov 19 '15 at 0:34
  • 1
    Have you tried this? bjornjohansen.no/load-gravity-forms-js-in-footer – pwbred Nov 19 '15 at 0:45
  • Thanks, adding the filter: add_filter('gform_init_scripts_footer', '__return_true'); did defer the scripts to load in the footer. – brandozz Nov 23 '15 at 21:59
2

With the help of smspaulb's link, brandozz has solved the issue by adding the following filter which defers the loading of the GravityForms script to the footer:

add_filter('gform_init_scripts_footer', '__return_true');

  • 1
    Just be sure to use caution when deregistering Wordpress jquery and loading in the footer. It may cause issues with certain plugins. – brandozz Sep 15 '16 at 2:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.