Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blizzrdof77/b7fc45fa9e886af437abf648ab2e9a34 to your computer and use it in GitHub Desktop.
Save blizzrdof77/b7fc45fa9e886af437abf648ab2e9a34 to your computer and use it in GitHub Desktop.
Remove Gravity Forms jQuery and all inline <script> tags
/**
* Force GFORM Scripts inline next to Form Output
*
* force the script tags inline next to the form. This allows
* us to regex them out each time the form is rendered.
*
* see strip_inline_gform_scripts() function below
* which implements the required regex
*/
function force_gform_inline_scripts() {
return false;
}
add_filter("gform_init_scripts_footer", "force_gform_inline_scripts");
/**
* Strip out GForm Script tags
*
* note: this diables post and pre render hooks which are triggered
* when the form renders so if you need these then it's important
* to manually re-add them in your compiled JS source code
*/
function strip_inline_gform_scripts( $form_string, $form ) {
return $form_string = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $form_string);
}
add_filter("gform_get_form_filter", "strip_inline_gform_scripts", 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment