The gform_name_suffix Gravity Forms PHP filter allows you to modify the “Suffix” label when creating the name suffix field.
Usage
add_filter('gform_name_suffix', 'change_suffix', 10, 2);
function change_suffix($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_suffix
Examples
Change the default name suffix label
This example changes the default name suffix label:
add_filter('gform_name_suffix', 'change_suffix', 10, 2);
function change_suffix($label, $form_id) {
return "Name Suffix";
}
Add a custom name suffix label for a specific form
This example adds a custom name suffix label for a specific form with the ID 5:
add_filter('gform_name_suffix', 'change_suffix_for_form', 10, 2);
function change_suffix_for_form($label, $form_id) {
if ($form_id == 5) {
return "Custom Suffix";
}
return $label;
}
Add a prefix to the name suffix label
This example adds a prefix to the name suffix label:
add_filter('gform_name_suffix', 'add_prefix_to_suffix', 10, 2);
function add_prefix_to_suffix($label, $form_id) {
return "Prefix: " . $label;
}
Change the name suffix label based on user role
This example changes the name suffix label based on the current user role:
add_filter('gform_name_suffix', 'change_suffix_based_on_role', 10, 2);
function change_suffix_based_on_role($label, $form_id) {
$current_user = wp_get_current_user();
if (in_array('administrator', $current_user->roles)) {
return "Admin Suffix";
}
return $label;
}
Remove the name suffix label
This example removes the name suffix label:
add_filter('gform_name_suffix', 'remove_suffix_label', 10, 2);
function remove_suffix_label($label, $form_id) {
return "";
}