How To Add SVG In WordPress

Do You Want To Add SVG In Your WordPress Site. Then You Are In Right Place. I Am Going To Show You How To Add SVG SUPPORT In WordPress. By Default WordPress Support all popular image, audio, and video file formats, but SVG is not among them. So Let’s Start.

What Is SVG?

SVG Stands For Scalable Vector Graphics. The Main Facility Of Using SVG Is Its Allow You To Enlarge Images Without Losing Any Image Quality.

By Default If You Try To Upload Any SVG In Your WordPress Site You Will See An Error Like The Screenshot.

Security Issue Doesn’t Allow SVG In WordPress

Upload SVG Without Any Plugin

For Making Sure You Can Upload SVG In Your WordPress Website You Need To Add The Following Code In Your Theme functions.php. Dont Know Where Is functions.php Check It Below.

Add SVG in WordPress

Now Check The Code Below And Paste It In Your functions.php

//add SVG to allowed file uploads
function svg_mime_types( $mimes ) {
  $mimes['svg'] = 'image/svg+xml';
  $mimes['svgz'] = 'image/svgz+xml';
  $mimes['exe'] = 'program/exe';
  $mimes['dwg'] = 'image/vnd.dwg';
  return $mimes;
add_filter('upload_mimes', 'svg_mime_types');

function svg_wp_check_filetype_and_ext( $data, $file, $filename, $mimes ) {
    $wp_filetype = wp_check_filetype( $filename, $mimes );
    $ext         = $wp_filetype['ext'];
    $type        = $wp_filetype['type'];
    $proper_filename = $data['proper_filename'];

    return compact( 'ext', 'type', 'proper_filename' );

Now Check The Magic You Can Upload Your SVG Without Any Problem.

Please follow and like us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Follow by Email