The gform_name_last Gravity Forms PHP filter is used to modify the “Last” label when creating the last name field.
Usage
add_filter('gform_name_last', 'change_last', 10, 2); function change_last($label, $form_id) { // your custom code here return $label; }
Parameters
- $label (string): The label to be filtered.
- $form_id (integer): The ID of the current form.
More information
See Gravity Forms Docs: gform_name_last
Examples
Change default last name label
This example changes the default last name label to “Last Name”:
add_filter('gform_name_last', 'change_last', 10, 2); function change_last($label, $form_id) { return "Last Name"; }
Change last name label based on form ID
This example changes the last name label based on the form ID:
add_filter('gform_name_last', 'change_last_based_on_form_id', 10, 2); function change_last_based_on_form_id($label, $form_id) { if ($form_id == 1) { return "Family Name"; } elseif ($form_id == 2) { return "Surname"; } return $label; }
Change last name label for all forms
This example changes the last name label to “Family Name” for all forms:
add_filter('gform_name_last', 'change_last_to_family_name', 10, 2); function change_last_to_family_name($label, $form_id) { return "Family Name"; }
Change last name label based on language
This example changes the last name label based on the site’s language:
add_filter('gform_name_last', 'change_last_based_on_language', 10, 2); function change_last_based_on_language($label, $form_id) { $language = get_locale(); if ($language == 'es_ES') { return "Apellido"; } return $label; }
Change last name label using a custom function
This example changes the last name label using a custom function:
add_filter('gform_name_last', 'change_last_with_custom_function', 10, 2); function change_last_with_custom_function($label, $form_id) { return custom_label_function($label); } function custom_label_function($label) { // Modify the label as needed $new_label = $label . " (Modified)"; return $new_label; }