Flatten a WordPress Website to HTML and CSS

By Forrest Smith - Drempd.com

I recently inherited a whole bunch of wordpress websites for one of my clients — in fact I think one of the first times it dawned on me that I would have to start working with these sites is when one of them got hacked and I got the call to see what I could do. I fixed it up, but once I started looking through the server, I saw many, many such websites — many archived for internal use, but all with outdated wordpress versions, numerous plugins, and obviously quite a few security issues. It wasn’t long before they all started being hit.

Note: While I am still working on my own version to create automated backups, I recently came across https://www.httrack.com/, which does a pretty good job of flattening a site down. I use this quite regularly.

Since most of these sites aren’t being actively edited, and are only really for archival and reference purposes, it made sense to see if I could just collapse them down to the minimum and do away with WordPress altogether. I found several “static website generators” that were plugins for wordpress. They all seemed promising, and they probably work on 90% of wordpress websites, but unfortunately they didn’t work on these ones.

I ended up building out my own system — it’s not even tied to wordpress, so I can use it on other websites, and it doesn’t need to reside on the same server.

Saving a Flattened Website

My website system first crawls the entire website, creating a full list of all pages on the site. It then just works through and saves each page as its own HTML file, and preserves the overall site structure, so pages that are separated into different sections stay where they are. It also works through each page, saving the relevant css, javascript, and image files, repathing those so everything works correctly.

My wordpress/website static generator (I think I like calling it a website flattener actually), seems to be working pretty well. I’ve been slowly working through the clients wordpress sites, getting them back up and running long enough at least to copy down a flattened version, which I can then upload back up in place of the wordpress website and worry quite a bit less about it being hacked into.

Uses for a Website Flattener

Archived Websites
The initial main use for this program was to save archived copies of websites, and to reduce the vulnerabilities and maintenance involved.  In the original use case, the client needed a new site created each year, but the older ones were referenced to build from. They no longer needed to edit or mess with the older sites.

New Site Launches
It has also come in handy for new site launches. For a recent project, we pulled down the existing client site, and launched our completely new and shiny one. Before we did so, I saved a flattened version of their site, so if we need to dig up any of the content that was on it, or see how things were originally structured, we have a full copy ready to go.

Content Archiving
Another company I’ve been working for likes to play with wording and other content on their site, but they also like to know what their site looked like three weeks ago. I’ve started to take reglar copies of the site so we have an easy point of reference to see how things changed, and to easily bring back text content if desired.

Future Updates

Since I’ve personally benefited quite a bit from my website saving system, I have a few planned updates to make my life easier, and potentially down the road I may even make it available to others for use. On my current list of updates:

Scheduling
Since one of my clients like to see how their content changes over time, it kind of makes sense to pull down a copy of their site at regular intervals. Currently I do it when I think about it, but it would be nice to schedule the saving process so I don’t have to worry about it.

Website Profiles
Since I’m the only one who currently uses the website flattener, it’s pretty rough, and the process of setting up a website within the system is less than ideal. Now that I’m using this for multiple websites, and on a somewhat routine basis, it makes sense to make the entire process easier on myself.

Public Version
I’m still deciding on if this is something I’ll make available to others, since cleaning things up and making projects nice for others to use is always quite a bit of work, but perhaps if thee was interest in such a tool I would.

Are you needing access to a handy static website generator? Feel free to contact me if you have a need for such a system, and I can work on creating a more polished, web-available version.