blog.lukhnos.org

Permanently Convert WordPress Blogs to Static Pages

Since I started using Tumblr to host my blogs, I no longer used WordPress. It's a great blog software, but even if you stopped writing blogs with it, you still need to run its software update from time to time for security. Because of that, plus other various personal reasons, I decided to convert all the WordPress blogs that I hosted on my own to static pages.

After some research online, the best solution I found for this task is Ammon Shepherd's WPStatic utility. Shepherd wrote extensively about his project (usage, origin, more details). The project has been around for a while, and the version hosted on github works with the latest WordPress. Here's a quick summary of what I do to "staticize" my blogs.

First, you need to know what WPStatic does:

The script is only one file, called wpstatic. Just place the file in your blog root, then run chmod +x wpstatic to make it executable, and then run ./wpstatic -h for help. Some of the above actions, such as permalink structure modification, can be toggled off.

Then, here's what I did:

  1. I ran some of the backups on Mac OS X and some on Linux. If you run the script on Linux, you need to change nothing. If you run the script on Mac OS X, you need to do a global replace to change every occurrence of sed -r to sed -E (that's because the sed that comes with Mac OS X comes from BSD).

  2. Run ./wpstatic but don't proceed with the wget backup (the actual page fetching). I ran this step to let the script close all the comments for me.

  3. Now this step is important. By default, the script changes your blog's permalink strcuture to something like http://example.com/year/month/day/post-name. This didn't work for me since some of my blog posts contain CJK titles, and CJK filenames work badly (a tragedy compounded by both URL encoding and file systems). Plus I have been using the structure like http://example.com/archives/123 for many years, and Google searchs on my blogs point to URLs like that. So, after the script changed the permalink structure, I had to go back to the admin page again, first change the permalink back to /archives/%post_id%, then I added a / at the end. The final permalink structure became /archives/%post_id%/, and this is great, because this actually caused the pages to be saved into something like /archives/123/index.html.

  4. Modifiy wp-includes/default-filters.php and comment out all actions that generate feed links. I turned off (commented out) these lines. You might want to remove more:

    add_action('wp_head','feed_links',2);
    add_action('wp_head','feed_links_extra',3);
    add_action('wp_head','rsd_link');
    add_action('wp_head','wlwmanifest_link');
    add_action('wp_head','rel_canonical');
    add_action('wp_head','wp_shortlink_wp_head',10,0);
    add_action('template_redirect','wp_shortlink_header',11,0);
    
  5. Modify your theme. In particular, remove the Meta links in the sidebar, the feed links in the header and the footer, and anything (such as the comment feed link in the single post page) that may generate RSS feeds, trackbacks or pingbacks — if you're converting your blog into static pages, those data is probably going to be meaningless since you are not updating the pages anymore. Search engines will still love your static pages.

  6. Run the script again, this time with wpstatic -p. You probably need to run a few times to make sure that it fetches no more than it should (i.e. no feeds, no trackback links, etc.)

  7. If your blog has database prefix wp_, the generated static page directory will be called wp-static. Inside the script has packed the MySQL dump and other static contents to wp-content.zip. You want to back that file up immediately.

  8. Backup your original blog directory for its scripts and settings.

  9. Remove the wp-content.zip in the generated static folder. Move static folder out. Remove the WordPress folder and rename the static folder to your blog's directory name.

Your mileage may vary. And most of important of all, backup everything before you perform any of the above conversion steps.