If you want to use a different CDN than the default sp-ao.shortpixel.ai when serving optimized images with Autoptimize, then please:
- Edit your DNS records to add a CNAME from
cdn.example.com
tono-cdn.shortpixel.ai
. This step might be slightly different depending on what CDN you use. Below you can see an example, but we recommend you to contact your CDN provider so they can help you set this up.- On the previous URL, replace
example.com
with your actual domain name. - If
cdn.example.com
is already being used on your DNS records, you can change it to whatever you want, likeimages.example.com
orimg.example.com
.
- On the previous URL, replace
- Make sure the new record (cdn.example.com) works as expected with an online tool like whatsmydns.net.
- Add the following code snippet to your functions.php file. You can use a plugin like this one.
add_filter("autoptimize_filter_imgopt_base_url","use_my_own_cdn"); function use_my_own_cdn($urlIn) { return str_replace("sp-ao.shortpixel.ai","cdn.example.com",$urlIn); }
Remember that you will need to change
cdn.example.com
to the new URL you just created, replacingexample.com
with your domain andcdn
with the CNAME you chose.Note: the filter name changed since version 2.5 of Autoptimize.
Example – Cloudflare #
Note: If you’re having SiteGround as your hosting provider you cannot properly set Cloudflare and use it as a CDN together with ShortPixel Adaptive Images. For more information, visit this page: CDN via Cloudflare for websites hosted at SiteGround, it this possible?
Here is a step-by-step example of how to set up the CNAME (previous step 1) on
Cloudflare. Please notice that we are not responsible for any changes made by Cloudflare that would invalidate the following steps. Therefore, if you encounter any issues while creating your new CNAME in your DNS records, please contact Cloudflare or your hosting provider.
- Enter your Cloudflare account
- Select the DNS section from the top menu.
- Add a new CNAME record from
cdn.your-domain.com
tono-cdn.shortpixel.ai
:Remember that
your-domain.com
should be changed to your actual domain, and thatcdn
should be changed to something else if it’s already being used. For example:
– images.myblog.com
– media.thebestshop.comThe little cloud must be orange so you can use the CDN features offered by Cloudflare.