You may use "## Title" to create a group of options.'; return $field; } function prepare_checkbox($field){ if(empty($field['choices'])) return $field; // Map '## Group' if(is_array($field['choices'])){ $found = false; $found_array = array(); foreach($field['choices'] as $k => $choice){ if(is_string($choice)){ $choice = trim($choice); if(strpos($choice, '##') === 0){ $choice = substr($choice, 2); $choice = trim($choice); $found = $choice; $found_array[$choice] = array(); }elseif(!empty($found)){ $found_array[$found][$k] = $choice; } } } if(!empty($found_array)){ $field['choices'] = $found_array; } } // Labels $labels = $this->walk($field['choices']); if(!empty($labels)){ $field['acfe_labels'] = $labels; } return $field; } function walk($choices = array(), $depth = 1, $labels = array()){ // bail early if no choices if(empty($choices)) return $labels; foreach($choices as $value => $label){ // optgroup if(is_array($label)){ reset($label); $key = key($label); if(!is_numeric($value)) $labels = array_merge($labels, array($value => $key)); $labels = $this->walk($label, $depth+1, $labels); } } return $labels; } function prepare_radio($field){ if($field['type'] !== 'radio' && $field['field_type'] !== 'radio') return $field; if(empty($field['choices'])) return $field; $choices = array(); foreach($field['choices'] as $value => $label){ if(is_array($label)){ $choices = $choices + $label; }else{ $choices = $choices + array($value => $label); } } $field['choices'] = $choices; return $field; } function field_wrapper($wrapper, $field){ $labels = acf_maybe_get($field, 'acfe_labels'); if(empty($labels)) return $wrapper; $wrapper['data-acfe-labels'] = $labels; return $wrapper; } } new acfe_field_checkbox(); endif;