Description
This filter can be used to dynamically add/remove CSS classes to a field.
Usage
add_filter( 'gform_field_css_class', 'custom_class', 10, 3 );
You can also specify this per form by adding the form id after the hook name.
add_filter( 'gform_field_css_class_6', 'custom_class', 10, 3 );
Parameters
- $classes string
The CSS classes to be filtered, separated by empty spaces, (i.e. “gfield custom_class”).
-
$field Field Object
Current field.
-
$form Form Object
Current form.
Examples
This example dynamically adds a custom class to all text fields:
add_filter( 'gform_field_css_class', 'custom_class', 10, 3 ); function custom_class( $classes, $field, $form ) { if ( $field->type == 'text' ) { $classes .= ' custom_textfield_class'; } return $classes; }
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFFormDisplay::get_field() in form_display.php.