There are hundreds of posts having “full” size images already published within post content.
Blog contributors have uploaded very large image (some like 3000px wide) files, by design these were fitted within css width:100% and height:100% so no one could notice this from the frontend until I started investigating the high page load timings.
The images inside the posts also have editorial formatting. Like “.align-right” etc.
I am in need of a technique to replace these with the full sized images with large ones.
Some approach:
- Get all posts
- regex content and find image tags
- try to find image id’s from the filenames
- replace post content with the full image urls
- update post
What do you think? Is there an easier way to accomplish this task?
Thank you.
I solved my own problem by using the creating a page using the following template. Just create and visit the page using the template below.
You will only be viewing the results with primitive pagination, follow the code and it’s easy.
Changes will not be saved until you visit /whatever-permalink-you-have/?updating=true
Caution
Please backup your database first if you decide to use this. It is always best to make trials on a duplicated database.
If you are using shortcodes that produce html output, they will be rendered into the post body. Please change the code accordingly.
This file uses PHP Simple HTML DOM Parser. It is expected to be in libs/ folder.