Since I had so many WordPress sites to convert into static HTML, I decided to write a nice little bash script for it. This will take care of everything except editing the theme files to take out links to RSS, meta links, or anything else you want removed. It will basically go through the list of steps outlined in this post: Convert WP to Static HTML Part 2. Just upload this script to your server (on the same level as wp-config.php) and run it as a command line program (ie: user@server $ ./wpstatic). Make sure to change the permissions on the file so that your user can execute it (ex. 744, or chmod u+x wpstatic).
What’s nice about the script is that it grabs the database info from the wp-config.php and autmagically formats the wget command. So basically, it does the following steps for you:
- Update the database to close comments on all posts and pages. Update the database permalink structure.
- Checks for a .htaccess file and for the correct rewrite code. If it doesn’t exist it creates one. If it exists but doesn’t think the right code is in there, it will append it to the end of the file.
- It makes a backup of the database before making the changes, and then again right after.
- Reminds you to change the theme files before asking if you would like it to run the wget command.
Ideally, you’ll have edited the theme files before hand, so that you can just run this script, and it will make a static copy of your WordPress blog.
Back by popular demand… I had to convert a lot of sites again, so I cleaned up the code and added some switches for skipping any of the steps.
Upload the script to your webhost/server where the WordPress files are located. Then run it on the terminal/PuTTY.
[code lang="bash"]./wpstatic [option][/code]
Check the git repository for the latest version: https://github.com/mossiso/WP-Static