BOBOBK

Seamless Migration from WordPress to Fully Static Hugo Website

MISCELLANEOUS

When evaluating the website, I found that a large portion of js, css, and other content was not fully utilized, but I didn’t know how to efficiently combine or remove them. I also wanted to try a static blog, so I decided to migrate to a completely static blog system. Here, I chose Hugo as the new system.

Main Steps

  • Download and install the WordPress to Hugo Exporter plugin and export blog content
  • Install Hugo static site generator
  • Modify configuration files
  • Generate the new static blog website
  • Modify DNS, website path, and other operations; audit the webpage

Download and install WordPress to Hugo Exporter plugin and export blog content

Log into the blog server and go to the blog directory

cd wp-content/plugins/
git clone https://github.com/SchumacherFM/wordpress-to-hugo-exporter.git
cd wordpress-to-hugo-exporter
php hugo-export-cli.php
mv /tmp/wp-hugo.zip ../../../


You can see the /tmp/wp-hugo.zip file has been generated in the blog root directory. Save it.

Install Hugo static site generator

It is recommended to download the binary package directly. Installing via Go takes more than an hour, which is too slow.
Go to the Hugo releases page and download the binary for your system. Here we take CentOS 64-bit as an example.

wget https://github.com/gohugoio/hugo/releases/download/v0.58.1/hugo_0.58.1_Linux-64bit.tar.gz
tar zxvf hugo_0.58.1_Linux-64bit.tar.gz
mv hugo /bin

Modify configuration files

First create the site, install the theme, and move the previously exported WordPress files into the content folder

hugo new site /www/wwwroot/bobobk.com
mv wp-hugo.zip /www/wwwroot/bobobk.com/content
cd /www/wwwroot/bobobk.com/themes
git clone https://github.com/rujews/maupassant-hugo.git
cd ../
vi config.toml

Here is a sample config file for your reference

baseURL = "https://www.bobobk.com"
languageCode = "zh-cn"
title = "Spring River Evening Guest"
hasCJKLanguage = true   # Support for Chinese, Japanese, Korean languages
theme = "maupassant-hugo"   # Theme name, must match the folder under themes
enableRobotsTXT = true  # Support robots.txt for crawlers
PaginatePath = "page"  # Pagination path
summaryLength = 140   # Summary length in characters
googleAnalytics = "UA-118758668-3"

[author]
    name = "Spring River Evening Guest"

[params]
    subtitle = "A personal website for a python learner"
    description = "Sharing python tips, learning notes and related content including python basics, machine learning, deep learning, scraping, and linux server knowledge."   # Meta description
    keywords = "python,linux,vps,server,machine learning,deep learning"   # Meta keywords
    toc = true  # Enable table of contents
    #busuanzi = true
    registerInfo = "ICP 18042563-1"
    related = true
    googleAd = "ca-pub-3250570391881200"

[[menu.main]]    # Main menu item for archives
    identifier = "archives"
    name = "Archives"
    url = "/archives/"
    weight = 3

[[menu.main]]    # Main menu item for about page
    identifier = "about"
    name = "About"
    url = "/about/"
    weight = 4

[params.cc]
    name = "Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License"
    link = "https://creativecommons.org/licenses/by-nc-nd/4.0/"

For detailed config instructions, please refer to the theme’s GitHub page. Here, I’ve mainly added archives, about, Google Analytics, and Google Ads.

Generate the new static blog website

Once the config file is ready and WordPress exported files are in the content folder, you can generate the full static website using Hugo:

hugo

You will see a public folder created, containing all the static site files. Change your web server’s root directory to point to this folder.

Modify DNS, website path, and other operations

If you use the same machine, no DNS change is needed. Otherwise, point the domain to the new IP. Since it’s a purely static site, you can also host it on GitHub Pages without needing a public server.

After migration, some advantages of migrating to Hugo static blog:

  • Binary Hugo installation is simple and fast
  • Supports Markdown, making blogging easy
  • Pure static site, faster response and rendering, significantly reducing server load
  • Fully preserves WordPress URLs, tags, and categories unchanged
  • Good for SEO
  • Secure, since it’s a purely static site with minimal security concerns

After migration, you can test site performance using Chrome tools:


As you can see, the performance on both desktop and mobile is excellent~~

Related