View Categories

How can I set up the plugin to serve images from a custom subdomain?

Important: If you are on a free plan or have purchased one-time credit packages, you will not be able to add a custom subdomain unless you use your own CDN to deliver the images instead of ShortPixel’s. Custom subdomains with ShortPixel’s CDN are exclusively available to users who have subscribed to an unlimited or monthly/yearly plan.
If all you want to do is use your own CDN to deliver the images, and you don’t care about the “Accept requests only from specific domains” feature, you can just follow this simpler tutorial.

If you want to use your own custom (sub)domain when using ShortPixel Image Optimizer (SPIO) or ShortPixel Adaptive Images (SPAI), instead of spcdn.shortpixel.ai for SPIO or cdn.shortpixel.ai for SPAI, follow these steps:

  1. Log in to your ShortPixel account and from the dashboard, click Associate Domains.
  2. Add your domain if it wasn’t there yet: How can I associate a domain to my account?
  3. Click on the Domain Settings icon on the right side of your associated domain to reveal the available options.
  4. Click on the Custom CDN Domain button.
  5. Think of a suitable subdomain name for the delivery of your images, such as cdn, img, images, media, and so on. For example, if your website is example.com and you choose img subdomain, your images will be served from img.example.com.
  6. Enter your preferred subdomain name in the “Enter your subdomain” text box.
  7. If you want to use your own CDN and do not want to use ShortPixel’s CDN, check the box “I use my own CDN”.
  8. Click on the red Setup Custom Domain button.
  9. Navigate to your domain’s DNS records, and add the CNAME you chose (e.g. img.example.com). If you’re unsure how, please contact your hosting provider for assistance.
    • If you want to keep using ShortPixel’s CDN, the CNAME must point to cdn.shortpixel.ai
    • If you want to use your own CDN, the CNAME must point to no-cdn.shortpixel.ai
  10. Once the CNAME record has finished propagating (which may take up to 48 hours), you can return to your ShortPixel dashboard where you should find the subdomain added to your list of associated domains.
  11. Optionally, for increased security, you may check the box “Accept requests only from specific domains” and enter a comma-separated list of domains. For example, if only example.com and wonderfulshop.com should serve images from img.example.com, set it up as shown in the following screenshot:
  12. Change the CDN domain / API URL on the WordPress settings.
    • If you are using SPAI, navigate to your WordPress dashboard and go to Settings > ShortPixel AI > Behavior > API URL. There, change the default URL to https://img.example.com/spai where img.example.com is the subdomain that you’ve set up above.
    • If you are using SPIO, navigate to your WordPress dashboard and go to Settings > ShortPixel > WebP/AVIF & CDN and enable the “Deliver the next generation images using the ShortPixel CDN” option. There, change the default URL to https://img.example.com/spio where img.example.com is the subdomain that you’ve set up above.
Please make sure you flush your website’s cache (whichever is applicable – caching plugin, server cache, CDN cache, and browser cache).