Migrate from Wordpress to Hugo: A Detailed Guide

  • Okzz
  • Monday, Jan 1, 0001
blog-image

Moving from WordPress to Hugo isn’t a light task, but it can be worth it for many reasons such as better speed, security, and cost efficiency. To help you through this process, we have created a detailed guide, taking you through each step, along with the corresponding commands.

Step 1: Backup your WordPress Content

Before making any major changes to your WordPress site, it’s essential to backup all of your content. This ensures you have a copy of all posts, pages, and other site content, in case anything goes wrong during the migration.

  1. Log in to your WordPress dashboard.
  2. Navigate to “Tools” -> “Export”.
  3. Select “All content” and click “Download Export File”. A XML file will be downloaded to your local machine.

Step 2: Install Hugo

Before you can import your WordPress content to Hugo, you need to install Hugo on your machine. Depending on your operating system, the installation commands will differ.

For macOS users:

Use Homebrew to install Hugo:

brew install hugo

For Windows users:

Use Chocolatey to install Hugo:

choco install hugo -confirm

For Linux (Debian) users:

Use Snap to install Hugo:

sudo snap install hugo

To check whether Hugo has been installed correctly, run:

hugo version

Step 3: Create a New Hugo Site

Now that Hugo is installed, you can create a new site. To do this, run the following command in your preferred directory:

hugo new site mynewsite

Replace “mynewsite” with your desired site name.

Step 4: Export WordPress Content to Hugo

For this step, we will use a tool called “exitwpforhugo”. This tool will help to convert your WordPress XML export file into Hugo-friendly markdown (.md) files.

  1. Download the tool from its GitHub repository:
git clone https://github.com/SchumacherFM/wordpress-to-hugo-exporter.git
  1. Move the WordPress XML file to the same directory as the tool you just downloaded. If your XML file is in your Downloads folder, you might use a command like this:
mv ~/Downloads/wordpress.xml ~/wordpress-to-hugo-exporter
  1. Run the exporter:
cd wordpress-to-hugo-exporter
python exitwpforhugo.py

After running this, you’ll find a new ‘build’ directory which contains your exported content.

Step 5: Move Exported Content to Hugo Site

Now, move the exported markdown files to your new Hugo site:

mv ~/wordpress-to-hugo-exporter/build/jekyll/your_wordpress_site_name/_posts/* ~/mynewsite/content/posts

Make sure to replace “your_wordpress_site_name” and “mynewsite” with your original WordPress site name and new Hugo site name respectively.

Step 6: Choose and Install a Hugo Theme

Hugo sites use themes to control the look and feel of the site. There’s a wide range of free and paid themes available for Hugo, which you can browse on the Hugo themes website. When you’ve found a theme you like, navigate to your new Hugo site’s directory:

cd mynewsite

Then, install the theme:

git submodule add https://github.com/username/theme-name.git themes/theme-name

Replace “username/theme-name” with the correct path

to your chosen theme.

In your config.toml file, set the theme:

theme = "theme-name"

Step 7: Test Your Site Locally

Before deploying your site, it’s a good idea to test it locally. Run:

hugo server

This will start a local server. By default, your site will be available at http://localhost:1313.

Step 8: Deploy Your Site

Hugo provides flexible deployment options. You can host your site on GitHub Pages, Netlify, AWS, and many more. For simplicity, let’s use Netlify:

  1. First, push your site to a GitHub repository.
  2. Then, log into Netlify and click on “New site from Git”.
  3. Select GitHub and authorize Netlify to access your repositories.
  4. Select your repository, and click on “Deploy site”.

Your site is now live!

Remember, Hugo is a static site generator, which means you’ll have to rebuild your site every time you add or update content. This process will vary depending on your host, but with Netlify, you can set up continuous deployment, which will automatically rebuild your site every time you push changes to your GitHub repository.

While migrating from WordPress to Hugo can be a complex process, it’s also an opportunity to streamline your site and make it more efficient. With this step-by-step guide, you’re well on your way to enjoying the benefits of Hugo.

comments powered by Disqus

Latest Posts

DevOps: Lab environment for continuous learning

If you are a DevOps engineer, systems engineer or SRE, it’s invaluable to have a lab environment that gives you free space to explore, build, break, fix, break, refactor, rebuild… and rebuild any part of the infrastructure you wish to work on.

Read more
View All Posts