AgentWP

  • Tutorials
  • Themes
  • Plugins
  • Services
  • Contact

How to Upload and Embed SVG Images in WordPress

SVG Image or the Scalable Vector Graphics image is a image file format for vector graphics. However, if you try to upload an SVG image to your WordPress website using the media uploader, you will get this error:

yourfile.svg has failed to upload due to an error
Sorry, this file type is not permitted for security reasons.

This is because SVG file is not white listed in the allowed file types that can be uploaded to WordPress via its media uploaded. To fix this issue, add this code to your theme’s functions.php file,

add_filter('upload_mimes', 'agentwp_upload_mimes');
functionagentwp_upload_mimes ( $existing_mimes=array() ) {
$existing_mimes['svg'] = 'mime/type';
return $existing_mimes;
}

Once you add this code to your theme’s functions.php file, you will not get any error while uploading the SVG file. Once uploaded, you can add the SVG image to your post and page using this HTML code:

<iframe style="margin:5px auto; display: block; width: 300px; height: 300px;" src="/wp-content/uploads/2011/11/yourimage.svg" width="300" height="300">

Don’t forget to replace the src with the source of your own uploaded SVG file.

Get useful WordPress related tricks, tips, tutorials and reviews delivered straight to your inbox.

StudioPress - Premium Wordpress Themes
ElegantThemes - Premium Wordpress Themes

Copyright © 2023 · AGENTWP · All Rights Reserved

Copyright © 2023 · awp on Genesis Framework · WordPress · Log in