The gform_password filter allows you to change the Password Field sub-label in Gravity Forms.
Usage
To apply your function to all forms, use the following code:
add_filter('gform_password', 'your_function_name', 10, 2);
To target a specific form, append the form id to the hook name (format: gform_password_FORMID):
add_filter('gform_password_6', 'your_function_name', 10, 2);
Parameters
- $sublabel (string): The sub-label to be filtered.
- $form_id (integer): ID of the current form.
More information
See Gravity Forms Docs: gform_password
Examples
Change the password sub-label to “Enter a password”
This example changes the password sub-label to “Enter a password” for the form with ID 185:
add_filter('gform_password_185', 'set_password_label', 10, 2);
function set_password_label($sublabel, $form_id) {
return 'Enter a password';
}
Change the password sub-label based on form ID
This example changes the password sub-label based on the form ID:
add_filter('gform_password', 'set_password_label_by_form', 10, 2);
function set_password_label_by_form($sublabel, $form_id) {
if ($form_id == 6) {
return 'Enter your secure password';
} elseif ($form_id == 7) {
return 'Create a strong password';
}
return $sublabel;
}
Add a custom prefix to the password sub-label
This example adds a custom prefix “MySite – ” to the password sub-label:
add_filter('gform_password', 'add_custom_prefix', 10, 2);
function add_custom_prefix($sublabel, $form_id) {
return 'MySite - ' . $sublabel;
}
Change the password sub-label to an empty string
This example removes the password sub-label by setting it to an empty string:
add_filter('gform_password', 'remove_password_sublabel', 10, 2);
function remove_password_sublabel($sublabel, $form_id) {
return '';
}
Change the password sub-label using a translation function
This example changes the password sub-label using a translation function (e.g., for a multilingual site):
add_filter('gform_password', 'translate_password_sublabel', 10, 2);
function translate_password_sublabel($sublabel, $form_id) {
return __('Enter your password', 'your-text-domain');
}