Using Gravity Forms ‘gform_disable_form_legacy_css’ PHP filter

The gform_disable_form_legacy_css filter allows you to disable the CSS for forms using legacy markup, typically forms created with Gravity Forms 2.4 and earlier.

Usage

To use the filter for all forms with legacy markup, simply add the following code:

add_filter('gform_disable_form_legacy_css', 'your_function_name');

Parameters

  • $disabled (bool): Determines whether to disable the CSS.

More information

See Gravity Forms Docs: gform_disable_form_legacy_css This filter was added in Gravity Forms v2.5 and is located in GFFormDisplay::get_form_enqueue_assets() in form_display.php.

Examples

Disable CSS for legacy forms

Disable the CSS for all forms with legacy markup:

function disable_legacy_css() {
    return true;
}

add_filter('gform_disable_form_legacy_css', 'disable_legacy_css');

Disable CSS for specific form ID

Disable the CSS for a specific form with a given ID (e.g., form ID 5):

function disable_legacy_css_for_form_5($disabled) {
    if (RGForms::post('gform_form_id') == 5) {
        return true;
    }
    return $disabled;
}

add_filter('gform_disable_form_legacy_css', 'disable_legacy_css_for_form_5');

Disable CSS for multiple form IDs

Disable the CSS for multiple form IDs (e.g., form IDs 5 and 7):

function disable_legacy_css_for_forms($disabled) {
    $form_ids = array(5, 7);
    if (in_array(RGForms::post('gform_form_id'), $form_ids)) {
        return true;
    }
    return $disabled;
}

add_filter('gform_disable_form_legacy_css', 'disable_legacy_css_for_forms');

Enable CSS for specific form ID

Enable the CSS for a specific form with a given ID (e.g., form ID 8) and disable for all other forms:

function enable_legacy_css_for_form_8($disabled) {
    if (RGForms::post('gform_form_id') == 8) {
        return false;
    }
    return true;
}

add_filter('gform_disable_form_legacy_css', 'enable_legacy_css_for_form_8');

Enable CSS for multiple form IDs

Enable the CSS for multiple form IDs (e.g., form IDs 8 and 9) and disable for all other forms:

function enable_legacy_css_for_forms($disabled) {
    $form_ids = array(8, 9);
    if (in_array(RGForms::post('gform_form_id'), $form_ids)) {
        return false;
    }
    return true;
}

add_filter('gform_disable_form_legacy_css', 'enable_legacy_css_for_forms');