Using Gravity Forms ‘gform_init_scripts_footer’ PHP filter

The gform_init_scripts_footer is a Gravity Forms filter that, when set to true, loads the form init scripts in the footer of the site rather than the default location, which is in the page body immediately after the form.

Usage

add_filter('gform_init_scripts_footer', '__return_true');

Parameters

  • __return_true: (boolean) A built-in WordPress function that returns true when called.

More information

See Gravity Forms Docs: gform_init_scripts_footer

Note: This filter does not occur when AJAX is being used within the form.

Note: As of Gravity Forms 2.5, scripts are included in the footer by default.

Examples

Load the form init scripts in the footer of your website.

add_filter('gform_init_scripts_footer', '__return_true');

Load the form init scripts in the footer only for forms with specific form IDs.

function my_custom_gform_init_scripts_footer($form) {
    // Load scripts in the footer for forms with ID 1 and 3
    if ($form['id'] == 1 || $form['id'] == 3) {
        return true;
    }
    return false;
}
add_filter('gform_init_scripts_footer', 'my_custom_gform_init_scripts_footer');

Load the form init scripts in the footer only when the form is displayed on a specific page.

function my_custom_gform_init_scripts_footer($form) {
    // Load scripts in the footer for the form on page with ID 42
    if (is_page(42)) {
        return true;
    }
    return false;
}
add_filter('gform_init_scripts_footer', 'my_custom_gform_init_scripts_footer');

Load form init scripts in the footer for specific post types

Load the form init scripts in the footer only when the form is displayed on a specific post type.

function my_custom_gform_init_scripts_footer($form) {
    // Load scripts in the footer for the form on "product" post type
    if (get_post_type() == 'product') {
        return true;
    }
    return false;
}
add_filter('gform_init_scripts_footer', 'my_custom_gform_init_scripts_footer');

Load the form init scripts in the footer only for users with a specific user role.

function my_custom_gform_init_scripts_footer($form) {
    // Get the current user
    $current_user = wp_get_current_user();

    // Load scripts in the footer for users with the "editor" role
    if (in_array('editor', $current_user->roles)) {
        return true;
    }
    return false;
}
add_filter('gform_init_scripts_footer', 'my_custom_gform_init_scripts_footer');