How to setup Photon CDN in WordPress without JetPack

Hey there! If you’re looking to speed up your WordPress website by using the awesome Photon CDN (Content Delivery Network) without installing the entire JetPack plugin, then you’ve come to the right place!

I know, JetPack can feel a bit bloated with all its extra features that some of us just don’t need. So, let’s keep it lean and mean while still getting the power of Photon.

First, let me tell you a little story. A while back, I was working on a website for a client who had a ton of images. The site was loading a bit slowly, and they were wondering if I could speed it up.

Naturally, I thought about using a CDN, but they didn’t want to deal with the JetPack plugin. That’s when I came across this simple, neat PHP script that allows you to use the Photon CDN directly without needing JetPack. It was like discovering a hidden gem!

How to setup Photon CDN in WordPress without JetPack

Alright, let’s dive in. Setting up Photon CDN in WordPress is actually easier than you think. All you need is a little PHP script, and you’re good to go. Here’s the script that makes it all happen:

Here’s a quick breakdown of how it works:

  1. DNS Prefetching: We tell the browser to prefetch DNS for the Photon servers (so that when it’s time to load images, it does so faster).
  2. Buffering Content: The script starts buffering the output of your WordPress site.
  3. Image Rewriting: It scans your site for image URLs and replaces them with URLs pointing to the Photon CDN (which means faster loading times for your images!).
  4. Randomized Server Choice: Photon CDN uses multiple servers (like i0.wp.com, i1.wp.com, etc.), and this script ensures that each image gets its own server (this helps with load balancing).

How to Add the Script to Your Site

Now, before we move ahead, I’ll tell you – adding this is super easy, but make sure you back up your site just in case. Alright, here’s what you need to do:

  1. Create a Plugin File:
    • Go to your wp-content/plugins directory in your WordPress installation.
    • Create a new file, maybe something like photon-cdn.php.
    • Paste the entire script above into this file.
  2. Activate the Plugin:
    • Go to the WordPress admin panel.
    • Navigate to PluginsInstalled Plugins.
    • You should see Photon CDN listed there.
    • Click Activate, and you’re good to go!

Why You Should Use This Over JetPack

I totally get it if you want to avoid JetPack – it’s a huge plugin with a lot of features you might not need. This lightweight Photon CDN setup gives you just the image CDN functionality (and nothing else), so it won’t bloat your site or slow it down.

Also, if you’re like me, you prefer having a bit more control over what gets added to your site. This method gives you exactly what you need and nothing more. It’s straightforward, and you can always tweak it if needed.

Final Thoughts

There you have it, folks! Now you’ve got a super simple, clean way to enable the power of Photon CDN on your WordPress site without JetPack. Your images will be served faster, your site will load quicker, and your visitors will love you for it.

And a big thanks to Zachary Scott for the awesome script that makes this possible. If you’re interested, you can check out more of his work here.

So, go ahead and give this a try! Let me know how it goes, and feel free to drop any questions in the comments. Happy WordPress-ing!


Discover more from Prime Inspire

Subscribe to get the latest posts sent to your email.

Leave a Reply

Scroll to Top

Discover more from Prime Inspire

Subscribe now to keep reading and get access to the full archive.

Continue reading