/** * Link: https://stackoverflow.com/questions/37386293/how-to-add-icon-in-select2 */ ( function ( $, rwmb ) { 'use strict'; const template = option => { if ( option.text.includes( '.*?<\/svg>/, '' ); return $( `${ option.text }` ); } return option.id ? $( `${ option.text }` ) : option.text; }; function initIconField( event, options ) { $( this ).select2( { ...options, templateResult: template, templateSelection: template, } ); } rwmb.$document .on( 'init_icon_field', '.rwmb-icon', initIconField ); } )( jQuery, rwmb );