Using Gravity Forms ‘gform_email_background_color_label’ PHP filter

The gform_email_background_color_label filter allows you to change the background color of the field label in the HTML email.

Usage

add_filter('gform_email_background_color_label', 'your_function_name', 10, 3);

Parameters

  • $color (string) – The current background color. The default is #EAF2FA.
  • $field (Field Object) – The current field.
  • $entry (Entry Object) – The current entry.

More information

See Gravity Forms Docs: gform_email_background_color_label

Examples

Set a specific color for all field labels

add_filter('gform_email_background_color_label', 'set_email_label_color', 10, 3);
function set_email_label_color($color, $field, $lead) {
    return '#CC99FF';
}

Change color based on field type

add_filter('gform_email_background_color_label', 'change_color_based_on_field_type', 10, 3);
function change_color_based_on_field_type($color, $field, $lead) {
    if ($field->type == 'text') {
        return '#FFCC99';
    }
    return $color;
}

Change color based on field ID

add_filter('gform_email_background_color_label', 'change_color_based_on_field_id', 10, 3);
function change_color_based_on_field_id($color, $field, $lead) {
    if ($field->id == 1) {
        return '#99CCFF';
    }
    return $color;
}

Change color for required fields

add_filter('gform_email_background_color_label', 'change_color_for_required_fields', 10, 3);
function change_color_for_required_fields($color, $field, $lead) {
    if ($field->isRequired) {
        return '#FF9999';
    }
    return $color;
}

Change color based on form ID

add_filter('gform_email_background_color_label', 'change_color_based_on_form_id', 10, 3);
function change_color_based_on_form_id($color, $field, $lead) {
    if ($lead['form_id'] == 2) {
        return '#99FF99';
    }
    return $color;
}