WP – SVG problems with WP 5

WP – SVG problems with WP 5

Oh man, WordPress 5.0 is becoming more of a problem than I thought.

So, something that I’ve noticed is that SVG files are not uploading. UGH.

I use a lot of SVG files.

Yeah, there’s a security risk, which happens because some punks hide bad code in their SVG files and give them out. But since I make my own SVG files, and check the code before I upload anything, I’m OK… and y’all should too.

Oh, tip:

If you have to get your vector files from places like flaticon.com, then, get the eps, and open it in Illustrator, and then export it. (I’m sure they have clean svg files, but I rarely use unedited files anyway..)

So, here’s the problem.

Suddenly, all my builds started telling me this

What????

Sorry, this file type is not permitted for security reasons.

 

First things first

Here is the code that allows svg uploads.

//add SVG to allowed file uploads
function add_file_types_to_uploads($file_types){

    $new_filetypes = array();
    $new_filetypes['svg'] = 'image/svg+xml';
    $file_types = array_merge($file_types, $new_filetypes );

    return $file_types;
}
add_action('upload_mimes', 'add_file_types_to_uploads');

Add that to the bottom of your functions.php file.

You should have a child theme, add this to the bottom of the child theme’s functions.php file. Get a free Divi child theme here, which has this code already included.

 

But it doesn’t work anymore. WHY NOT????? (btw, even svg plugins won’t work either. ugh)

The answer is here.. but who cares, it doesn’t work, and we need to make it work.

The fix

Step 1. Keep the code intact.

Yeah, that code is correct, it’s just the WP has blocked it for some reason, and it’ll come back soon. (probably) So yeah, leave it.

 

Step 2. Add this to the svg files.

So open the svg file in a text editor, and add this in the front.

<?xml version="1.0" encoding="utf-8"?>

Turns out this will fix it. huh.

At the moment, it’s not the svg files that are the problem, it’s WP being cranky.

 

BUT, unfortunately, the easiest fix for this is to edit the svg files.

So yeah, anyways, that’s how you can upload svg files again. UGH.

 

I’m not happy with WP 5. I’ll have Gutenberg + Divi review up soon.

 

Photo by Sandro Katalina on Unsplash

ps. I’ve seen that 4.9.9 has the same problem.. and this will fix it just the same.

Update: it seems that the SafeSVG plugin can circumvent this problem easily. So there you go. Problem solved. haha. I’mma go install that now.

 

Get Breakdance

Breakdance is, in my opinion, the best page/site builder on the market, which is why all my tutorials use Breakdance. It's also why I have an affiliate link. You don't pay extra, but I get a little commission, so it helps support the site. Thanks!

Get ACF Pro

Another essential plugin for site building. This isn't an affiliate link, it's just for convenience.

Get WP Codebox Pro

If you'd like an easier to use, and more advanced code management plugin (instead of just editing and making files yourself) then WP codebox pro is for you. Adding php, js, and even SCSS. Pretty nice! Affiliate link below.

Blank Plugin

Sort of blank. It's made to be easy to use with the tutorials. Download and edit any way you see fit.
    Leave a Reply

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

    New tutorials

    Designing Beyond the Brief
    Disable Gutenberg Editor on some ACF pages
    ACF flexible content fields in Breakdance 2.4
    Making a lightbox from a CPT Loop

    Got a question? ask!

    If you have any question about the content on this page, feel free to send me an email by clicking the button below.

    newsletter? sign up!

    Sign up to the newsletter for updates on tutorials, news, and offers.

    Join the cypher!

    An awesome membership program for Breakdance Builder users coupled with an inclusive, friendly community.

    Got a question?

    If you have a question about something on this page, send me an email, and hopefully I can answer, and we can solve it!