Using Gravity Forms ‘gform_address_zip’ PHP action

The gform_address_zip Gravity Forms PHP filter is used to modify the “Zip” label when creating an address zip field.

Usage

To apply the filter to all forms:

add_filter('gform_address_zip', 'change_address_zip', 10, 2);

To apply the filter to a specific form, for example form Id 5:

add_filter('gform_address_zip_5', 'change_address_zip', 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_zip

Examples

Change the default address zip label

This example modifies the default address zip label:

add_filter('gform_address_zip', 'change_address_zip', 10, 2);

function change_address_zip($label, $form_id) {
    return "Address Zip";
}

Change the address zip label for a specific form

This example modifies the address zip label for the form with id 5:

add_filter('gform_address_zip_5', 'change_address_zip_for_form', 10, 2);

function change_address_zip_for_form($label, $form_id) {
    return "Custom Zip Label";
}

Change the address zip label based on the form ID

This example changes the address zip label depending on the form’s ID:

add_filter('gform_address_zip', 'change_address_zip_by_form_id', 10, 2);

function change_address_zip_by_form_id($label, $form_id) {
    if ($form_id == 1) {
        return "Form 1 Zip";
    } elseif ($form_id == 2) {
        return "Form 2 Zip";
    } else {
        return $label;
    }
}

Add a prefix to the address zip label

This example adds a prefix to the address zip label:

add_filter('gform_address_zip', 'add_prefix_to_address_zip', 10, 2);

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

Change the address zip label using a translation function

This example changes the address zip label using a translation function for multilingual sites:

add_filter('gform_address_zip', 'translate_address_zip', 10, 2);

function translate_address_zip($label, $form_id) {
    return __("Translated Zip", "your-text-domain");
}