An incredibly simple way to supercharge a WordPress website.

There doesn't seem to be much information out there on using a CDN with WordPress. So I though I'd put together an incredibly simple tutorial. First, some back-story. Skip to the next heading if you just want the instructions.

Back Story

We've got a pretty sophisticated infrastructure running and all of its associated properties. It's powerful, and it handles pretty sizeable chunk of traffic these days! But there's one thing which isn't sitting on that infrastructure. Not coincidentally, it's the only part of the puzzle that's given us some trouble since we launched. The Ghost Marketplace.

In the future, the marketplace will be a completely custom application. Right now, however, we have an interim placeholder to simply serve as a bit of a showcase gallery for themes built with Ghost. This little site it built with WordPress and is actually the only property we have which is running on PHP. As a result, it's the one thing which is simply pointed at my little shared hosting account - rather than our supercharged infrastructure.

All of that would be fine, except that the Marketplace by its very nature has a great deal of images... and with our traffic levels... it sucks up a pretty unholy amount of bandwidth. Causing my entire shared hosting account to be suspended, several times in the last month.

One of the most effective (and simple) ways to dramatically speed up a WordPress website is to offload your assets to an external Content Delivery Network (CDN) - which also takes a great deal of load off your servers. And, in some cases, your shared server bandwidth limit.

Bizarrely, there doesn't seem to be much information out there for how to use a CDN with WordPress. A few Google searches turns up only the (endless) lists of "How to use WordPress with MaxCDN" sponsored marketing posts, TL:DR; Download a plugin and pay them $10 a month, and some paid plugins.

But what if you already have a different CDN? Or (god forbid) you just want to use something other than MaxCDN?

Setting up a CDN with WordPress in Two Simple Steps

In this post I'm simply going to address offloading your images to a CDN. Very similar things can be done to additionally offload your CSS and JavaScript - but I'll let you work that out for yourself.

1. Get a CDN Account with a Pull Zone

First you're going to need a CDN account with a CDN provider. There are plenty to choose from. At the moment we use EdgeCast. It doesn't really matter who you use, so long as they support Pull Zones (Sometimes also referred to as a "Customer Origin").

There are two main ways of working with a CDN. A Push Zone and a Pull Zone. A Push Zone is when you upload your files directly to your CDN provider (you push them) and it serves them. A Pull Zone is when your CDN mirrors your server, copying everything that's on it and serving a copy (it pulls them in).

The simplest (and usually cheapest) is a Pull Zone. Set one of these up with your provider and point it at your domain. That's pretty much it. It will now copy all files on your server and host a copy of them. Magic.

It should give you a new url from which you can access your files. something like

After a little while (usually an hour) you should be able to access all of your files on this URL the same as if you were looking at your own site. So an image which currently exists on:

Can now also be accessed on


2. Change your WordPress settings to point at the CDN's copy of the files instead of your own

So now that all those images are available on the CDN. The last step is to make all of your WordPress posts point to those images on the CDN. There are two ways of doing this. Either you can go through an update every post manually (that was a joke, don't do this) - or - you can do the much simpler 1 minute fix to change them all automatically.

Add the following to your theme's functions.php file (making sure you replace the example CDN url with your own):

function my_cdn_upload_url() {
    return '';
add_filter( 'pre_option_upload_url_path', 'my_cdn_upload_url' );

That's all there is to it. All your images will now be loaded from the CDN instead of from your local server.

Best of all - because it's a pull-zone - you can turn it off at any time. Change your mind? Just delete those lines from your functions.php file and all your images will load from your own server again. They're always backed up and stored on your own server.

You can also write filters (or change paths directly in your theme files, if applicable) to change the location of your CSS or JavaScript files to be loaded from the CDN.

Give it a try!