I'm trying to use SVG image with wp_get_attachment_image()
but it is generating very weird output at the front end of the website.
To support SVG file type I've first added the following function in my theme's functions.php
file
/*** enable svg support ***/
function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
Then inside my theme file I'm trying to use the SVG images like this:
$image_id = 3679;
echo wp_get_attachment_image( $image_id, array( 57, 58 ), false, array( "class" => "icon" ) );
So, it is supposed to generate an html like this:
<img width="57" height="58" src="http://example.com/wp-content/uploads/2016/09/something.svg" class="icon">
But instead it is generating HTML like this:
<img width="1" height="1" src="http://example.com/wp-content/uploads/2016/09/something.svg" class="icon" alt="briefcase">
As you can see due to the width="1"
and height="1"
, that image is not showing up. But what I don't understand is where this 1 value is coming from as I'm not passing that.
Does anyone know a fix for this issue?