Created
February 5, 2018 21:30
-
-
Save camtheperson/2a31eee4e83c1cb514c6eb0109bd6fb1 to your computer and use it in GitHub Desktop.
Gravity Forms jQuery Fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gravity Forms jQuery fix | |
*/ | |
function gc_deregister_default_jquery() { | |
wp_deregister_script('jquery'); | |
} | |
add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\gc_deregister_default_jquery'); | |
function inject_jquery_above_gravity_form($content = '') { | |
global $jquery_already_injected; | |
if ( !isset($jquery_already_injected) ) { | |
$jquery_already_injected = true; | |
$content .= "</script>\n"; | |
$content .= "<script src='https://code.jquery.com/jquery-1.12.4.min.js'></script>\n"; | |
$content .= "<script>"; | |
} | |
return $content; | |
} | |
add_filter('gform_cdata_open', __NAMESPACE__ . '\\inject_jquery_above_gravity_form'); | |
function enqueue_jquery() { | |
global $jquery_already_injected; | |
if (!isset($jquery_already_injected)) { | |
wp_enqueue_script('jquery'); | |
} else { | |
wp_enqueue_script('jquery', '//fake-jquery-script.js', [], null); | |
function gc_remove_fake_jquery_script($tag) { | |
$tag = (strpos($tag, 'fake-jquery-script') !== false) ? '' : $tag; | |
return $tag; | |
} | |
add_filter('script_loader_tag', __NAMESPACE__ . '\\gc_remove_fake_jquery_script'); | |
} | |
} | |
add_action('wp_footer', __NAMESPACE__ . '\\enqueue_jquery', 9); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment