The project I'm working on, I couldn't find an easy way to have WordPress create the thumbnails sizes I needed without tons of waste, nor to simultaneously generate WebP versions, so I disabled the thumbnails, I upload a full-size jpg or png, and then I manually generate my WebP and other sizes and copy them to the uploads. A custom PHP function handles building responsive <picture>
.
However, I'd like to avoid the media library loading up the full-size image as the thumbnail all the time, as it's a waste of bandwidth. I'd like to point to a small WebP or JPG version that is not in the library but in the uploads folder and have it load that image instead. The file name is almost the same, just needs to be appended with _width
(width being a number) which I could do with strtr
or something.
Is there a way to access the Media Library File column with a function and a hook/filter so I can change the src path to the thumbnail image? I'd also need to avoid PDF
, SVG
and TXT
file uploads and just target JPG
or PNG
files. If it's not possible, I'll have to generate a thumbnail with a custom size.
wp_enqueue_media
might be the way, but not sure how to go about it. I'll add a screenshot.image_size
s I wanted based on a file prefix, but no one responded. As it is, I already have 2,000 images do to responsive and the site isn't live, and I couldn't keep waiting without a reply, so this is the route I took. Everything works great and I use a plugin to organize uploads into directories. Just need to modify the admin thumbnail src somehow.