Exclude folder from uploading to CDN

Is it possible to skip a folder from being uploaded to the CDN and serve it directly from the local storage?

Thanks in advance!

  • Vaughan
    • Support/SLS MockingJay

    Hi Webxopt

    I have created a mu-plugin for you which will allow you to exclude specific folder names.

    Please download and unzip the attached zipfile.

    Then open up & edit the enclosed file: wpmudev-img-skip-smush-CDN.php

    Add the foldername you want to exclude (including the / before it.) to the array on line 29.

    private $skip_folders = array( '/foldername' );

    Seperate each foldername with a comma , if you want to exclude multiple folders.

    Then upload this file to /wp-content/mu-plugins/

    Now ANY folders named /foldername will not be uploaded to the SmushCDN.

    Hope this helps.

  • Webxopt
    • Design Lord, Child of Thor

    Hi, thanks for this. I uploaded the plugin and got the following fatal error: –

    Fatal error: Uncaught Error: Call to undefined function is_plugin_active() in /home/brenclos/public_html/wp-content/mu-plugins/wpmudev-img-skip-smush-CDN.php:17 Stack trace: #0 /home/brenclos/public_html/wp-settings.php(293): include_once() #1 /home/brenclos/public_html/wp-config.php(185): require_once(‘/home/brenclos/…’:wink: #2 /home/brenclos/public_html/wp-load.php(37): require_once(‘/home/brenclos/…’:wink: #3 /home/brenclos/public_html/wp-admin/admin.php(34): require_once(‘/home/brenclos/…’:wink: #4 /home/brenclos/public_html/wp-admin/index.php(10): require_once(‘/home/brenclos/…’:wink: #5 {main} thrown in /home/brenclos/public_html/wp-content/mu-plugins/wpmudev-img-skip-smush-CDN.php on line 17

    The site is experiencing technical difficulties. Please check your site admin email inbox for instructions.

    Any ideas what that was is about? I thought that was a fairly common function. For your info, I have hummingbird active, but the CDN is currently switched off.

  • Nithin
    • Support Wizard

    Hi Webxopt ,

    I could notice the fatal error, please try the following patch which should fix the issue. It’s working when tested in my system. You don’t have to edit the attached file it should out of the box exclude the /gravity_forms folder, and by default checks within the /uploads folder.

    You’ll have to upload the attached file as mu-plugins, the same way as done before. Please do let us know how that goes. Have a great day ahead.

    Kind Regards,

  • Vaughan
    • Support/SLS MockingJay

    Hi Webxopt

    Just a brief explanation of the process.

    Just a thought. Am I supposed to put a full path in to the folder name, or do you assume that the named folder is in the /uploads/ folder?

    No, it’s a really simple and basic script.

    What it does is grabs the source URL of the image itself.

    so, for example, the url might look like:


    another img with URL:


    What the script does is just a simple string check, so it checks for the presence of that string in the skip_folders array()

    skip_folders = array( ‘12345’ );

    the above, noting that we haven’t included a / before 12345, the script will search the URL for that string.

    Therefore, in the above URLS, you might want to only skip images in the folder 12345.

    The script will detect that string, it’s present, so will skip it. However, because there’s no slash, it will in the case of the 2nd URL, it will also see 12345 in the filename img12345.jpg, therefore it will skip that too.

    So we add a / at the beginning, so it will only then find /12345 and will ignore other files like IMG12345.jpg

    As i said, it’s really quite basic, but does the job.

    Hope that explains it a bit better. :slight_smile:

  • Webxopt
    • Design Lord, Child of Thor

    Hi, that’s great. Thanks for the explanation and the revised version works a treat. If you have a look at https://www.brenclosures.co.nz/contact/ you can see the that large map image at the top of the page is from the CDN, but if you click on any of the top 2 locations email addresses (sales@brenclosures.co.nz), a modal box opens with a form and the captcha is direct from the server.

    Seems to have solved the issues with Edge too.

    Cheers and Thanks for the help

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.