WP Themehat

How To Add SVG In WordPress Without Any Plugin!

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.

Add SVG Without Any Plugin

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.

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' );
}
add_filter('wp_check_filetype_and_ext','svg_wp_check_filetype_and_ext',10,4);

Now Check The Magic You Can Upload Your SVG Without Any Problem. You Can Read More About Required File For WordPress Theme

Exit mobile version