Shortcode return vs echo. Return messes with data URLs, echo does not
Thanks to @fuxia, adding data to allowed protocols fixes the problem and I can happily use return. add_filter( ‘kses_allowed_protocols’, function ( $protocols ) { $protocols[] = ‘data’; return $protocols; });