{"id":115,"date":"2023-05-23T18:15:01","date_gmt":"2023-05-23T18:15:01","guid":{"rendered":"http:\/\/svg-presentation.local\/?page_id=115"},"modified":"2023-05-23T19:16:13","modified_gmt":"2023-05-23T19:16:13","slug":"allowing-svg-upload","status":"publish","type":"page","link":"https:\/\/jeffmcnear.com\/wpsvg\/allowing-svg-upload\/","title":{"rendered":"ALLOWING SVG UPLOAD"},"content":{"rendered":"\n<p>While direct insertion of .SVG code into the HTML block will work just fine, getting a .SVG file into the media library is a different thing. By default WordPress does not allow .SVG upload &#8211; mainly because the format being code based could contain malicious scripts.<\/p>\n\n\n\n<p>This block of code in a theme&#8217;s function file would grant .SVG upload permission<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>\/\/add SVG to allowed file uploads\nfunction add_file_types_to_uploads($file_types){\n    $new_filetypes = array();\n    $new_filetypes&#91;'svg'] = 'image\/svg+xml';\n    $file_types = array_merge($file_types, $new_filetypes );\n    return $file_types;\n}\nadd_action('upload_mimes', 'add_file_types_to_uploads');<\/code><\/pre>\n\n\n\n<p>There are several plugins on the repository that achieve the same end here are the top two:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/wordpress.org\/plugins\/safe-svg\/\" target=\"_blank\" rel=\"noreferrer noopener\">Safe SVG<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/wordpress.org\/plugins\/svg-support\/\" target=\"_blank\" rel=\"noreferrer noopener\">SVG S<\/a><a href=\"https:\/\/wordpress.org\/plugins\/svg-support\/\">upport<\/a><\/li>\n<\/ul>\n\n\n\n<p>Both of these plugins will sanitize any uploaded .SVG file before allowing it into the media folder.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While direct insertion of .SVG code into the HTML block will work just fine, getting a .SVG file into the media library is a different thing. By default WordPress does not allow .SVG upload &#8211; mainly because the format being code based could contain malicious scripts. This block of code in a theme&#8217;s function file [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-115","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/jeffmcnear.com\/wpsvg\/wp-json\/wp\/v2\/pages\/115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jeffmcnear.com\/wpsvg\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/jeffmcnear.com\/wpsvg\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/jeffmcnear.com\/wpsvg\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jeffmcnear.com\/wpsvg\/wp-json\/wp\/v2\/comments?post=115"}],"version-history":[{"count":0,"href":"https:\/\/jeffmcnear.com\/wpsvg\/wp-json\/wp\/v2\/pages\/115\/revisions"}],"wp:attachment":[{"href":"https:\/\/jeffmcnear.com\/wpsvg\/wp-json\/wp\/v2\/media?parent=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}