Subscribe On YouTube

Join other subscribers and enjoy other Divi video tutorials!

How To Temporarily Allow SVG File Uploads In Divi For Admin Users Only

Nelson Miller Profile Orange
In this tutorial I will show you how to securely allow SVG file uploads in Divi for admin users only with an innovative temporary option.

▶️ Please watch the video above to get all the exciting details! 👆

Overview of SVG Files In WordPress And Divi

Security Risk

As you may know if you ever tried to upload an SVG file to Divi or WordPress, it is not allowed for security reasons. This does not mean that SVGs are inherently bad or unsafe, but rather this file type is XML-based, which means they are potentially vulnerable to external attacks. By preventing SVG uploads, WordPress is keeping spammers and hackers away from your site.

SVGs Are Helpful

But SVG images and icons are also great for many reasons, and very useful when building websites with Divi. SVG stands for Scalable Vector Graphics, which means they are not pixelated and will not appear blurry when resized, so this is a major advantage. SVGs are perfect for graphics and icons.

Where To use SVGs In Divi

SVGs are essentially an “image” format, so you can use SVGs anywhere you can add an image. This means you can add SVGs files to the Blurb module (which has an option to choose from an icon or an image), the Image module, or any other Divi module with an image picker field.

Our Clever Solution For Safe SVG Uploads In Divi

We are excited to announce the development of a clever way to securely enable SVG file uploads! This solution is only available in our Divi Assistant plugin, which has a setting to enable this new feature. Instead of allowing SVG file uploads all the time, instead we have created a way to only allow SVG file uploads temporarily after clicking a button.

How It Works

It is a clever and seamless solution with no extra hassle. You simply click the buttons to upload an image like usual in Divi or WordPress, and you will see a new button which is added by the plugin called “Temporarily Allow SVG Uploads” which is conveniently located on the WordPress file upload screen. All you have to do is click the button to enable the permission, then select the file on your computer like usual. It’s that easy! As soon as the file is uploaded, the permission is automatically disabled, making it super secure! To add another file, simply click the button again – it’s that easy!

enable svg upload permission settings in Divi Assistant

When you go to the WordPress Media Library and add a new file, you will see the “Temporarily Allow SVG Uploads” button added below the “Select Files” button.

temporarily enable SVG uploads button in WordPress

When you click on any image picker field in Divi modules, you will see the “Temporarily Allow SVG Uploads” button added to the Upload Files tab below the “Select Files” button.

temporarily enable SVG uploads button in WordPress from Divi Builder

Be sure to watch the video above to see this in action!

Alternative Method (Less Secure): Code Snippet To Allow SVG Uploads In Divi For Admin Users

If you do not own the Divi Assistant plugin and don’t need any of the 100+ main features, you can enable SVG uploads in Div with an alternative method by using a PHP code snippet. The one nice thing about using our code specifically with this method is that we do limit it to only admin users, which is better than any other code solution out there on other blogs and tutorials – so we hope you do appreciate that! However, this will still mean SVGs are enabled all the time even when not uploading images, which is just how it is.

Where To Paste The PHP Code

1. Divi Assistant
If you are using our Divi Assistant plugin, simply paste the code in the PHP tab in the custom code window in the Divi Visual Builder.

2. Child Theme
If you are using a child theme, paste this code into the functions.php file. If you don't have a child theme, you can generate a child theme directly on your site or download our free child theme.

3. Code Snippet Plugins
Otherwise, install a dedicated code snippet plugin, create a new snippet, and paste this code into the PHP code editor.

If you need help understanding where to paste the code, please check out our complete guide about where to add custom PHP code snippets in Divi.

 * Allow SVG
 * @param $mimes
 * @return mixed
if (!function_exists('pac_da_mime_types')):
    function pac_da_mime_types($mimes)
        $mimes['svg'] = 'image/svg+xml';
        $mimes['svgz'] = 'image/svg+xml';

        return $mimes;
 * Fixes the issue in WordPress 4.7.1 being unable to correctly identify SVGs
 * @param $data
 * @param $file
 * @param $filename
 * @param $mimes
 * @return array|mixed|null
if (!function_exists('pac_da_fix_mime_type_svg')):
    function pac_da_fix_mime_type_svg($data = null, $file = null, $filename = null, $mimes = null)
        $ext = isset($data['ext']) ? $data['ext'] : '';
        if (strlen($ext) < 1) {
            $exploded = explode('.', $filename);
            $ext = strtolower(end($exploded));
        if ('svg' === $ext) {
            $data['type'] = 'image/svg+xml';
            $data['ext'] = 'svg';
        } elseif ('svgz' === $ext) {
            $data['type'] = 'image/svg+xml';
            $data['ext'] = 'svgz';

        return $data;
 * Allow SVG To Upload From Admin Side Only To Specific Roles
 * @return void
if (!function_exists('pac_da_allow_svg')):
    function pac_da_allow_svg()
        if (current_user_can('administrator')) {
            add_filter('upload_mimes', 'pac_da_mime_types');
            add_filter('wp_check_filetype_and_ext', 'pac_da_fix_mime_type_svg', 75, 4);

    add_action('admin_init', 'pac_da_allow_svg');
Enable SVG Uploads admin only and temporary feature Settings in the Divi Assistant Plugin

Subscribe For More Things Like This!

At the start of each month, we send out a recap newsletter from the month before with family news, Divi news, our latest tutorials, and product news. Occasionally, if the news is too exciting to wait, we will send out another email separate from the monthly newsletter. That’s what you get when you subscribe, and of course you can unsubscribe if you are no longer interested!

Blog Post Optin

Leave A Response!

By commenting you agree to our Blog & YouTube Comments Policy


Submit a Comment

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

Recent Posts


Your Cart