Skip to content

Instantly share code, notes, and snippets.

@RadGH
Last active May 16, 2022 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RadGH/aedfc2e143528bcc078d1d4ff923ac79 to your computer and use it in GitHub Desktop.
Save RadGH/aedfc2e143528bcc078d1d4ff923ac79 to your computer and use it in GitHub Desktop.
Gravity Forms: Add field type class to every gfield
<?php
// Make every gravity form field add its input type as a class.
// Example (added class: gfield-type-radio):
// fieldset id="field_136_31" class="gfield gfield-type-radio ..."
// Some other types: name, email, html, select, ...
function aa_add_input_type_gravity_forms( $form ) {
foreach ( $form['fields'] as $field ) {
if ( $field instanceof GF_Field ) {
$field->cssClass .= 'gfield-type-' . $field->get_input_type();
}
}
return $form;
}
add_filter( 'gform_pre_render', 'aa_add_input_type_gravity_forms' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment