[{"data":1,"prerenderedAt":37},["ShallowReactive",2],{"49mjiXmctb":3},{"id":4,"slug":5,"title":6,"excerpt":7,"meta_title":8,"meta_description":9,"page_content":10,"featured_image":26,"fields":27,"tags":29,"published":33,"published_at":34,"created_at":35,"updated_at":36},"6ef0142d-de21-4dfc-8894-c25e868783e0","notes/wordpress-image-optimiser-built-with-ai","I Built a WordPress Image Optimiser With AI (Instead of Reaching for Another Plugin)","Images are the number one cause of slow WordPress sites. Rather than bolt on another plugin to clean up after the fact, I built a small tool with AI that optimises them at source. Here's the thinking.","I Built a WordPress Image Optimiser With AI","Images are the top cause of slow WordPress sites. Instead of another plugin, I built a small tool with AI that optimises them at source. The thinking behind it.",{"blocks":11},[12,20],{"id":13,"data":14,"type":19},"bbecf57f-9463-4a56-87fd-2887114b7ff5",{"url":15,"title":16,"provider":17,"subtitle":18},"https://www.youtube.com/watch?v=NuUNwVpKU5E","Side Quest: I Built a WordPress Image Optimiser With AI","youtube","The original video this piece is based on.","video",{"id":21,"data":22,"type":25},"6b685a1f-7966-4683-8bdd-30f20a0c258e",{"content":23,"maxWidth":24},"\u003Cp>This one was a genuine side quest. I was part way through filling a WordPress site with content using AI, and I got to the images. The obvious lazy route is to upload them as they are and then install a plugin like Smush to compress them afterwards. I stopped, because I've learned the same lesson enough times: the better answer is almost always to fix the problem at source, not to bolt on another plugin to clean up the mess later.\u003C/p>\u003Cp>So instead I spent a few minutes building a small tool that optimises the images before they ever reach WordPress. Here's the thinking, because the principle matters more than the script.\u003C/p>\u003Ch2>Why images are worth this much fuss\u003C/h2>\u003Cp>If you've read my piece on \u003Ca href=\"/notes/why-your-wordpress-site-is-slow\">why WordPress sites get slow\u003C/a>, you'll know images are the single most common culprit. Someone uploads a photo straight off a phone, four thousand pixels wide and several megabytes, into a slot that's twelve hundred pixels wide. The browser downloads the whole thing and shrinks it. Do that across a gallery and the page is carrying a load of weight nobody ever sees the benefit of. Get the images right and you often halve the page size on its own.\u003C/p>\u003Ch2>Optimise at source, not after the fact\u003C/h2>\u003Cp>The plugin approach treats the symptom. You let oversized images in, then run something across the library to compress them. It works, but you're now maintaining another plugin, and you've still done the upload twice in effect: once heavy, once cleaned up.\u003C/p>\u003Cp>Optimising at source flips it. Before an image goes into WordPress, you convert it to a modern format, WebP, and compress it to a sensible quality. The file that lands in your media library is already small. There's nothing to clean up afterwards because nothing heavy ever went in. I've used this pattern on other content systems for years, and there was no reason not to bring it to WordPress.\u003C/p>\u003Ch2>What I actually built\u003C/h2>\u003Cp>It's a small Node script that uses the Sharp library to do the compression and the WebP conversion, then pushes the result into WordPress through its own tooling so that WordPress still generates its responsive image sizes the way it normally would. That last part matters: you want your optimisation and WordPress's own resizing to cooperate, not fight. I had it handle a single file for testing and a batch for the real run, pointing at a central media folder rather than uploading into individual fields.\u003C/p>\u003Cp>The honest version includes the bit that tripped me up on camera: authentication. A local WordPress without HTTPS won't take an application password, so getting a script to upload into the media library needs a little setup. None of it is hard, but it's the kind of detail a polished tutorial quietly edits out, and I'd rather you know it's there.\u003C/p>\u003Ch2>The bigger point: build the small tool, don't make do\u003C/h2>\u003Cp>The reason I'm writing this up isn't really about images. It's that building the exact small tool you need has gone from a luxury to a five minute job. For years the sensible thing was to make do with a plugin that did roughly what you wanted, plus four things you didn't, because writing your own was too slow to justify. That maths has changed. I described what I wanted, the tool got built, and now I have a reusable image uploader that puts optimised images into WordPress every time.\u003C/p>\u003Cp>That's the part worth taking away. I can hand that tool to someone else and they'll get optimised images without thinking about it, because the good behaviour is baked into the tool rather than relying on everyone remembering to run a plugin. Stop making do, build the thing that fits.\u003C/p>\u003Ch2>If your WordPress images are the problem\u003C/h2>\u003Cp>If your site is slow and the images are the obvious cause, this is squarely the kind of thing I help with, either fixing the images and setup directly, or building you a small bit of tooling so it stays fixed. You can \u003Ca href=\"/wordpress\">see how I work with WordPress\u003C/a>, or book a free half-hour surgery and I'll give you an honest read on what's weighing your site down and the cheapest way to sort it.\u003C/p>","lg","wysiwyg","",{"author":28},"Headless Digital",[30,31,32],"wordpress","ai","performance",true,"2026-07-04T08:00:00+00:00","2026-06-20T05:36:07+00:00","2026-07-04T08:00:02.104695+00:00",1783152046681]