Title: Allow select2 fields to render HTML again
Last modified: March 1, 2024

---

# Allow select2 fields to render HTML again

 *  [tg247](https://wordpress.org/support/users/tg247/)
 * (@tg247)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/allow-select2-fields-to-render-html-again/)
 * I had the same need for rendering HTML in select2 fields as in the support forum(
   [https://support.advancedcustomfields.com/forums/topic/allow-select2-fields-to-render-html-again/](https://support.advancedcustomfields.com/forums/topic/allow-select2-fields-to-render-html-again/)).
   After debugging, I came to this solution:
 *     ```wp-block-code
       add_action( 'acf/input/admin_footer', function() {
       ?>
       <script>
       acf.add_filter('select2_args', function( args ){
         args.templateSelection = function (selection) {
           var $selection = jQuery('<span class="acf-selection"></span>');
           // use acf.escHtml(selection.text) instead of acf.strEscape(selection.text))
           $selection.html(acf.escHtml(selection.text));
           $selection.data('element', selection.element);
           return $selection;
         }
         return args;
       });
       </script>
       <?php
       });
       ```
   
 * Maybe the ACF team would implement a filter to control the use of `acf.escHtml()`
   over `acf.strEscape()`? That would be really nice and would be more futureproof
   than overwriting it like this.
   Thanks and kind regardsThomas
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fallow-select2-fields-to-render-html-again%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

The topic ‘Allow select2 fields to render HTML again’ is closed to new replies.

 * ![](https://ps.w.org/advanced-custom-fields/assets/icon.svg?rev=3207824)
 * [Advanced Custom Fields (ACF®)](https://wordpress.org/plugins/advanced-custom-fields/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/advanced-custom-fields/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/advanced-custom-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/advanced-custom-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/advanced-custom-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/advanced-custom-fields/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [tg247](https://wordpress.org/support/users/tg247/)
 * Last activity: [2 years, 3 months ago](https://wordpress.org/support/topic/allow-select2-fields-to-render-html-again/)
 * Status: not a support question