How to add a CDN to WordPress



If your website takes a long time to load, say over five seconds, then you’ll lose up to 50% of your website visitors before they even get there. One way which you can improve your website load times and reduce the preload bounce rate is by using a content delivery network.

Adding a content delivery network is a fantastic way to boost your website into stratospheric speeds through delivering common media files from a number of points in the network instead of from one server which can bottleneck traffic and lead to slower speeds.

There is a lack of well-written info out there about how exactly to add a CDN to your WordPress site that doesn’t involve using a paid-for plugin, so we’ve created this simple how-to guide just for you.

Setting up a CDN with WordPress isn’t difficult. In fact, there are just two simple steps which you’ll need to do to improve your website speed.

Here we’re going to explain offloading your image files onto a CDN. You can do this to offload your JavaScript and CSS too, but we’re sure that you’re bright enough to figure that out yourself after using this guide.

Step one: Acquire a content delivery network account with a pull zone

There are loads of different CDN providers out there that you can use for your site. The only proviso on who you use will be if they support pull zones or ‘customer origin’ as some folks call them.

Working with a CDN involves a push zone or a pull zone. A push zone is where you ‘push’ images onto your CDN and it serves them. A pull zone is where you mirror your server somewhere in cyberspace and it serves a copy when handling a request. Got it?

The simplest version, and the one that costs the least is the pull zone. If you set one up and point it at your domain, it does the work for you. Your images are now hosted on a server and you don’t have to worry too much about it.

You will be given a new url to access your files from, such as:

It’ll take a short time to configure, but you’ll be able to access all your images at this URL, hopefully within an hour or so. Once this happens, you’ll be able to access your images on the CDN as if they were on your own server.

Step two: Point WordPress at the CDN and not your server

Next, you’ll need to add a code snippet to your site’s functions.php file. Make sure you edit the snippet to your own domain URLs.

function my_cdn_upload_url() {

return '';


add_filter( 'pre_option_upload_url_path', 'my_cdn_upload_url' ); 

That’s it! Not even difficult. Now your site’s images will load from the CDN and not your sever, meaning a much faster service around the world. You can also change the location of your JavaScript and CSS to the CDN as well.

If you need any help with WordPress CDNs – or any aspect of developing your WordPress site – get in touch with us via our contact form or by calling our London office on 020 8123 6303.