Skip to content

Instantly share code, notes, and snippets.

@eriteric
Last active October 13, 2021 16:55
Show Gist options
  • Save eriteric/5d6ca5969a662339c4b3 to your computer and use it in GitHub Desktop.
Save eriteric/5d6ca5969a662339c4b3 to your computer and use it in GitHub Desktop.
Load gravity forms JS in footer
// GF method: http://www.gravityhelp.com/documentation/gravity-forms/extending-gravity-forms/hooks/filters/gform_init_scripts_footer/
add_filter( 'gform_init_scripts_footer', '__return_true' );
// solution to move remaining JS from https://bjornjohansen.no/load-gravity-forms-js-in-footer
add_filter( 'gform_cdata_open', 'wrap_gform_cdata_open' );
function wrap_gform_cdata_open( $content = '' ) {
$content = 'document.addEventListener( "DOMContentLoaded", function() { ';
return $content;
}
add_filter( 'gform_cdata_close', 'wrap_gform_cdata_close' );
function wrap_gform_cdata_close( $content = '' ) {
$content = ' }, false );';
return $content;
}
@TeemuSuoranta
Copy link

From GF 2.5 this breaks the forms (that have coniditional logic). See https://community.gravityforms.com/t/gf-2-5-7-5-is-broken/10323/8

I'd advice not using this any more and removing it anywhere where it is added.

@JoryHogeveen
Copy link

Correct, this code is redundant since GF 2.5+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment