I was exploring the idea of migrating my wordpress.com blog to a Headless CMS + Git + Hugo setup. The initial site could be created in few minutes, thanks to the amazing work done by Netlify. However since I was using a free wordpress.com account, the content migration process ended up having few hiccups. Below notes might help someone who wants to try out the same.
Export all the content from the Wordpress.com
- Log into wordpress.com admin
- Select Export option under Tools menu on the left
- Click on the Start Export
- Select All content from the radio button options
- Click Download Export File
- Your data will be downloaded as an XML file
Setup Docker and Docker-compose
We can’t install the Hugo conversion plugin on Wordpress.com, hence we need to setup a local Wordpress instance. The easiest and the quickest way to do this is to use Wordpress on Docker.I used docker4wordpress and it was very easy to setup.
Before anything, we need Docker installed and running. I’m using Manjaro Linux (based on Arch) and setting up Docker was as simple as below.
sudo pacman -S Docker
sudo systemctl start docker
sudo systemctl enable docker
docker --version
For docker4wordpress, we need Docker Compose
sudo pacman -S docker-compose
docker-compose --version
If you want to be able to run docker as a regular user (without typing sudo), add your user to the docker user group. However the official Arch WIKI warns about some security concerns around that.
Setup docker4wordpress
Once the Docker and Docker compose is available, we can move onto the docker4wordpress. Assuming that you already have Git, let’s clone the docker4wordpress repository.
git clone https://github.com/wodby/docker4wordpress.git
Now from the project root, run
sudo docker-compose up -d
If you receive the following error, go ahead and restart your machine before doing anything else.
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
Who would thought that even Linux needs a bit of love with a restart ;-)
Now let’s Start the docker-compose one more time. If you see the below messages, we should be able to access the local Wordpress instance using http://wp.docker.localhost:8000
jay@Serenity docker4wordpress]$ sudo docker-compose up -d
Creating network "docker4wordpress_default" with the default driver
Creating my_wordpress_project_mariadb ... done
Creating my_wordpress_project_php ... done
Creating my_wordpress_project_portainer ... done
Creating my_wordpress_project_traefik ... done
Creating my_wordpress_project_mailhog ... done
Creating my_wordpress_project_nginx ... done
Default database user, password and database name are all wordpress, database host is mariadb
Import all the content into the local Wordpress
Now, Log into the admin portal and import the previously exported XML content file by
- Click on Tools –> Import
- Click Run Importer link under option wordpress
- Select the XML from the file system
- Click Upload files and Import button
- Click Import Attachments checkbox
- Click Submit button
Install Hugo Exporter plugin on local Wordpress
- Download a zip file of wordpress-to-hugo-exporter repo
- Log into Wordpress admin portal
- Select Plugins option from the left menu
- Click Add New button at the top
- Select the wordpress-to-hugo zip file to import
- Once the setup is completed, make sure to activate the new plugin
Run Hugo Exporter
- Log into Wordpress admin portal
- Select Tools menu from the left panel
- Select Export to Hugo option’
- This will download everything into a file named hugo-export.zip
Happy ever after
Not really. The export makes the life easy as the posts get converted into markdown files. However you still have to tinker your posts here and there to get them working on your static site.
Have you found any other easy way to migrate old Wordpress content over to a static site?
After exploring few options, I ended up replacing the whole thing with Ghost, which is the underlying platform of this blog. Have a look at Ghost when you get a chance, its amazing!.
See you soon!