Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. getdave created this gist Nov 12, 2015.
    25 changes: 25 additions & 0 deletions strip-unwanted-gravity-forms-jquey-and-inline-scripts.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    /**
    * 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);