The gform_address_country filter in Gravity Forms allows you to modify the “Country” label when creating the address country field.
Usage
add_filter('gform_address_country', 'change_address_country', 10, 2);
Parameters
- $label (string): The label to be filtered.
- $form_id (int): The current form’s ID.
More information
See Gravity Forms Docs: gform_address_country
Examples
Change the Default Address Country Label
This example changes the default address country label for all forms.
add_filter('gform_address_country', 'change_address_country', 10, 2);
function change_address_country($label, $form_id) {
// Change the address country label
return "Address Country";
}
Change Address Country Label for a Specific Form
This example changes the address country label for a specific form with form ID 5.
add_filter('gform_address_country_5', 'change_address_country', 10, 2);
function change_address_country($label, $form_id) {
// Change the address country label
return "Address Country";
}
Change Address Country Label Based on Form ID
This example demonstrates how to change the address country label based on the form ID.
add_filter('gform_address_country', 'change_address_country_based_on_form_id', 10, 2);
function change_address_country_based_on_form_id($label, $form_id) {
// Change the address country label based on form ID
if ($form_id == 5) {
return "Country (Form 5)";
}
return $label;
}
Change Address Country Label to Include an Asterisk
This example changes the address country label to include an asterisk, indicating a required field.
add_filter('gform_address_country', 'change_address_country_to_required', 10, 2);
function change_address_country_to_required($label, $form_id) {
// Add an asterisk to the address country label
return $label . " *";
}
Change Address Country Label Based on Language
This example changes the address country label based on the site’s language.
add_filter('gform_address_country', 'change_address_country_by_language', 10, 2);
function change_address_country_by_language($label, $form_id) {
// Get the site's language
$language = get_bloginfo('language');
// Change the address country label based on language
if ($language == "en-US") {
return "Address Country";
} elseif ($language == "es-ES") {
return "País";
} else {
return $label;
}
}