How to convert a Wordpress Blog to a static site using wget
Wordpress is the largest CMS used on the web and it has become a common choice. It is very easy to get a up and running website for your blog or business. But sometimes maintenance can be hard, especially if you run an old blog which you have not updated in a while. Running an out of date wordpress can be dangerous, so if you want to keep your old wordpress content page, you can create a static copy of the website, so you don’t need to run a wordpress installation in the backend anymore.
In this article we will be showing you two different methods for converting a wordpress page to static html using command line tools.
Be Aware Converting a wordpress website to a static page will only work for static content websites. If you are using lots of dynamic PHP or Javascript e.g to submit form data or to load content dynamically with Javascript, the converted website might not function properly!.
Option 1) Generate static html using wget
Wget is a popular GNU utitliy which allows to download files on the internet from the command line. It can also be used for archiving web pages or even to mirror whole websites and save its html content. This is excactly what we need in order to convert our wordpress to static html.
You can use the following wget command to archive your wordpress blog automatically.
wget -r -nd --no-clobber --page-requisites --convert-links --domains example.org --no-parent --wait=1 --limit-rate=500K \
example.org/
Explanation:
-r follows every link on the website the –domains option limits this to only follow internal links. The -page-requisites option makes sure that all static files (e.g. css, images, js files) are being preserved while downloading.
Lastly we set the –limit-rate=500 and -wait=1 options to prevent wget to use all of our bandwidth.
Option 2) Generate static html with httrack
Another way to generate static html pages from your Wordpres installation is to use the tool httrack. This is basically a command line webcrawler and has some additional features like concurrent downloads and read from local cache.
First we need to install httrack on our system:
Install httrack on Ubuntu/Debian
To install httrack we can use our favorite package manager.
sudo apt install httrack
Install httrack on Fedora/CentOS
On CentOS we can use yum.
sudo yum install httrack
Install httrack on ArchOS
sudo pacman -y httrack
To use HTTrack to convert your WordPress site to a static website on the command line, follow these steps:
1.) Open a terminal window and navigate to the directory where you want to save the static website.
2.) Use the following command to create a mirror of your WordPress site:
httrack "http://your-wordpress-site.com" -O "./output-directory" "+*.css" "+*.js" "+*.png" "+*.jpg" "+*.gif" -v
Replace “http://your-wordpress-site.com” with the URL of your WordPress site and “./output-directory” with the path to the directory where you want to save the static website. The options “-O” and “-v” specify the output directory and verbose mode, respectively. The options “+.css”, “+.js”, “+.png”, “+.jpg”, and “+*.gif” tell HTTrack to download files with these extensions.
4.) Wait for HTTrack to finish downloading your WordPress site. This may take a few minutes, depending on the size of your site.
- Once the download is complete, you should have a static version of your WordPress site in the output directory. You can test the site by opening the index.html file in your web browser.
Note that the static site generated by HTTrack will not have any dynamic functionality, such as comments, search functionality, or contact forms. You will need to use a separate tool or service to implement these features on your static site.