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.

 

Leave a Reply

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

    New tutorials

    Why no ads?

    Hi, I'm PK, and I maintain and publish content on this site for two reasons.

    1. To give back to the community. I learned so much from people's tutorials and StackOverflow that I wanted to contribute and help others.

    2. To provide a more structured learning experience. People struggle to find the course that guides them from start to finish, based off of real life experience, and my courses provide that.

    The only "ads" I have here are for my own courses, and maybe an affiliate link, but that's it. They fund the website resources and provide more motivation for me to produce better content.

    Any bit of interest helps. Even sharing with your friends, suggesting my courses to your developer or designer, or subscribing to my YT channel, or joining our Discord. Thanks and I'll see you around!

    There's a newsletter!

    Sign up to the newsletter for the occasional updates on courses, products, tutorials, and sales.