Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save getdave/3a26392824853ce7f80d to your computer and use it in GitHub Desktop.
Save getdave/3a26392824853ce7f80d 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);
@blizzrdof77
Copy link

Thank you!

@samuel-hauser
Copy link

And even in 2021 a heartfelt thank you.

@m-hamza
Copy link

m-hamza commented Dec 12, 2022

how to use?

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