Created
April 24, 2025 17:25
-
-
Save faisalahammad/efee8b004f83946c4fd702888da4ae0e to your computer and use it in GitHub Desktop.
Custom WordPress code to display different "required fields" text for different Gravity Forms. Perfect for multilingual websites that need form validation messages in multiple languages. Just modify the form IDs and customize the text for each language you need. Add to your theme's functions.php file or use with a code snippets plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add multilingual support for required field text in Gravity Forms | |
* | |
* @author Faisal Ahammad <[email protected]> | |
*/ | |
add_filter( 'gform_required_legend', 'dynamic_required_legend', 10, 2 ); | |
function dynamic_required_legend( $legend, $form ) { | |
$form_id = $form['id']; | |
// Change text based on which form is showing | |
if( $form_id == 1 ) { | |
return '<span class="gfield_required gfield_required_text">* Required fields (English)</span>'; | |
} | |
elseif( $form_id == 2 ) { | |
return '<span class="gfield_required gfield_required_text">* Campos obligatorios (Spanish)</span>'; | |
} | |
elseif( $form_id == 3 ) { | |
return '<span class="gfield_required gfield_required_text">* Champs obligatoires (French)</span>'; | |
} | |
// Default text for any other forms | |
else { | |
return '<span class="gfield_required gfield_required_text">* Required fields</span>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screenshot