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.
- Log in to your WordPress dashboard.
- Navigate to “Tools” -> “Export”.
- 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:
For Windows users:
Use Chocolatey to install Hugo:
choco install hugo -confirm
For Linux (Debian) users:
Use Snap to install Hugo:
To check whether Hugo has been installed correctly, run:
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:
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.
- Download the tool from its GitHub repository:
git clone https://github.com/SchumacherFM/wordpress-to-hugo-exporter.git
- 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
- 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:
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:
Step 7: Test Your Site Locally
Before deploying your site, it’s a good idea to test it locally. Run:
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:
- First, push your site to a GitHub repository.
- Then, log into Netlify and click on “New site from Git”.
- Select GitHub and authorize Netlify to access your repositories.
- 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.