I was recently working on a custom WordPress widget where I wanted to include an image in the widget title. For security reasons, WordPress sanitizes the html so it was not working for me. I searched and searched on the internets but ran into solutions that were bulky and didn’t work for me. After looking into the
text widget source code which allows html, I found this useful filter:
apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
I adapted it to my WordPress plugin for the widget like so:
$instance['title'] = '<img src="https://www.some_website.com/images/logo.png">My Logo'; apply_filters( 'widget_text', $instance['title'] );
And that does it!