The gform_name_first filter allows you to modify the “First” label for the first name field in Gravity Forms.
Usage
add_filter('gform_name_first', 'change_first', 10, 2);
function change_first($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_first
Examples
Change First Name Label
This example changes the default first name label to “First Name”:
add_filter('gform_name_first', 'change_first', 10, 2);
function change_first($label, $form_id) {
return "First Name";
}
Change First Name Label Based on Form ID
This example changes the first name label depending on the form ID:
add_filter('gform_name_first', 'change_first_based_on_form', 10, 2);
function change_first_based_on_form($label, $form_id) {
if ($form_id == 1) {
return "Your First Name";
} elseif ($form_id == 2) {
return "Child's First Name";
}
return $label;
}
Add Required Asterisk to First Name Label
This example adds a required asterisk to the first name label:
add_filter('gform_name_first', 'add_required_asterisk', 10, 2);
function add_required_asterisk($label, $form_id) {
return $label . " *";
}
Wrap First Name Label in Custom HTML
This example wraps the first name label in a custom HTML span:
add_filter('gform_name_first', 'wrap_label_in_span', 10, 2);
function wrap_label_in_span($label, $form_id) {
return '<span class="custom-label">' . $label . '</span>';
}
Add Font Awesome Icon to First Name Label
This example adds a Font Awesome icon to the first name label:
add_filter('gform_name_first', 'add_font_awesome_icon', 10, 2);
function add_font_awesome_icon($label, $form_id) {
return '<i class="fas fa-user"></i> ' . $label;
}