Using Gravity Forms ‘gform_address_street2’ PHP action

The gform_address_street2 filter in Gravity Forms allows you to modify the “Street 2” label when creating the address street 2 field.

Usage

To apply the filter to all forms:

add_filter('gform_address_street2', 'change_address_street2', 10, 2);

To apply the filter to a specific form, use the form ID (e.g., form ID 5):

add_filter('gform_address_street2_5', 'change_address_street2', 10, 2);

Parameters

  • $label (string): The label to be filtered.
  • $form_id (integer): The current form’s ID.

More information

See Gravity Forms Docs: gform_address_street2

Examples

Change the default address street 2 label

add_filter('gform_address_street2', 'change_address_street2', 10, 2);

function change_address_street2($label, $form_id) {
    return "Address Street 2";
}

Change the address street 2 label for a specific form

add_filter('gform_address_street2_5', 'change_address_street2', 10, 2);

function change_address_street2($label, $form_id) {
    return "Apt/Suite/Unit";
}

Change the address street 2 label conditionally based on form ID

add_filter('gform_address_street2', 'change_address_street2', 10, 2);

function change_address_street2($label, $form_id) {
    if ($form_id == 5) {
        return "Apt/Suite/Unit";
    } else {
        return "Address Street 2";
    }
}

Change the address street 2 label and add a custom prefix

add_filter('gform_address_street2', 'change_address_street2', 10, 2);

function change_address_street2($label, $form_id) {
    return "Custom Prefix - " . $label;
}

Change the address street 2 label using a translation function

add_filter('gform_address_street2', 'change_address_street2', 10, 2);

function change_address_street2($label, $form_id) {
    return __("Address Line 2", "your-text-domain");
}

Place the code examples in the functions.php file of your active theme.