In the 6.2.7 version of Advanced Custom Fields, ACF blocked the use of HTML in the select2 fields “Security Fix – The default render template for select2 fields no longer allows HTML to be rendered resolving a potential XSS issue”
This caused issues for us as we Material Symbols & Icons in the fields in our theme to display icons.
Below is some code you can use to again allow HTML to be rendered in your select2 fields, and this keeps it to admin and editors only.
// Allow ACF select2 fields to display google material icons again - ACF patched in Version 6.2.7
add_action('acf/input/admin_footer', function() {
if (!current_user_can('administrator') && !current_user_can('editor')) {
return;
}
?>
<script>
acf.add_filter('select2_args', function(args) {
args.templateSelection = function(selection) {
var $selection = jQuery('<span class="acf-selection"></span>');
$selection.html(acf.escHtml(selection.text));
$selection.data('element', selection.element);
return $selection;
}
return args;
});
</script>
<?php
});