Skip to content

Instantly share code, notes, and snippets.

@swoboda
Created May 26, 2020 21:26
Show Gist options
  • Save swoboda/badb3576de68eb58cce5ba152afbf365 to your computer and use it in GitHub Desktop.
Save swoboda/badb3576de68eb58cce5ba152afbf365 to your computer and use it in GitHub Desktop.
Option groups in the Gravity Forms drop down field
<?php
// Do NOT include the opening php tag
add_filter( 'gform_field_choice_markup_pre_render', function ( $choice_markup, $choice, $field ) {
if ( $field->get_input_type() == 'select' ) {
$choice_value = rgar( $choice, 'value' );
if ( $choice_value === 'optgroup-start' ) {
return sprintf( '<optgroup label="%s">', esc_html( $choice['text'] ) );
} elseif ( $choice_value === 'optgroup-end' ) {
return '</optgroup>';
}
}
return $choice_markup;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment