functions – Possible to hook into Media Library preview File column and use a custom image?


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 all the time, as it’s a waste. 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 path to the 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.

liquidRock 2 months 2021-10-07T14:31:42-05:00 0 Answers 0 views 0

Leave an answer