Developer
Move a WordPress Post to Hugo: Export, Markdown, TOML, Upload
ยท 6 min read
To move a WordPress post to Hugo, you need five things: the post's content and date from the WordPress export file, that content as Markdown, a site config in TOML, files on the server that the web server is allowed to read, and article structured data so search engines still see a dated blog post. Emojar has a free tool for each step: the XML Formatter, HTML to Markdown, the JSON to TOML Converter, the Chmod Calculator and the Article Schema Generator. They all run in your browser, so the export file, your drafts and your server paths stay on your computer.
The example is a small food blog called Kitchen Notes. It has a few dozen posts on WordPress, and the owner wants a plain static site built with Hugo. We'll follow one post, "Sourdough on a Tuesday", from 12 March 2019, all the way to the live server.
How do you read a WordPress export file?
In WordPress, Tools โ Export gives you one XML file with every post in it. It arrives as one very long line, which is hard to read in a text editor. Paste it into the XML Formatter, leave Mode on Beautify (2 spaces) and click Format XML.
A trimmed version of the Kitchen Notes export comes out like this:
<item>
<title>Sourdough on a Tuesday</title>
<link>https://kitchen-notes.example/sourdough-on-a-tuesday/</link>
<wp:post_date>
<![CDATA[2019-03-12 08:15:00]]>
</wp:post_date>
<wp:post_name>
<![CDATA[sourdough-on-a-tuesday]]>
</wp:post_name>
<content:encoded>
<![CDATA[<h2>Feeding the starter</h2><p>Feed it <strong>twice</strong> ...]]>
</content:encoded>
</item>
Elements that hold only text, like <title>, stay on one line. The formatter keeps CDATA sections as they are and puts each one on its own indented line, so the post body inside <content:encoded> is easy to spot and copy. wp:post_name is the old URL slug, which you'll want to keep, and wp:post_date is the publish date.
If you trimmed the file by hand and cut a tag in half, the formatter reports the unclosed or mismatched tag. It only checks that tags nest and close properly. It doesn't validate against an XSD schema, and a WordPress export doesn't need that.
How do you convert the post's HTML to Markdown?
Hugo content files are Markdown, and WordPress stores posts as HTML. Copy the HTML from inside the CDATA brackets (everything between <![CDATA[ and ]]>) and paste it into HTML to Markdown. The Markdown appears as you type.
For this input:
<h2>Feeding the starter</h2><p>Feed it <strong>twice</strong> the day before. See <a href="https://kitchen-notes.example/starter/">my starter notes</a>.</p><ul><li>100 g flour</li><li>100 g water</li></ul>
the output is:
## Feeding the starter
Feed it **twice** the day before. See [my starter notes](https://kitchen-notes.example/starter/).
- 100 g flour
- 100 g water
The Headings menu switches between # ATX (the default, with ## marks) and Setext (underlined). Keep ATX, since it's what most Hugo themes and editors expect. Code blocks come out fenced with three backticks, and bullet lists use -.
The converter is built on Turndown. Elements with no Markdown version keep only their text, so a WordPress gallery block or an embed turns into plain words or disappears. Check for them after each conversion. Simple tables come through as text, and complex ones need some tidying by hand.
Download the result as a .md file, then add Hugo front matter at the top. Reuse the old slug from wp:post_name there so the URL survives the move.
How do you write the Hugo config in TOML?
Hugo reads its settings from hugo.toml by default. Many starter themes show the config as JSON in their docs, and it's easy to sketch your settings as JSON first. Paste it into the JSON to TOML Converter:
{
"baseURL": "https://kitchen-notes.example/",
"title": "Kitchen Notes",
"languageCode": "en-gb",
"params": {
"description": "Bread, soup and weeknight dinners",
"mainSections": ["posts"],
"logo": null
},
"menus": {
"main": [
{ "name": "Posts", "pageRef": "/posts", "weight": 1 },
{ "name": "About", "pageRef": "/about", "weight": 2 }
]
}
}
The first attempt stops with an error. TOML has no null value, so the converter names the key it can't write, here params.logo, and doesn't drop it silently. Kitchen Notes has no logo yet, so tick Leave out null values (TOML has no null) and list them. A notice under the output then says "Left out 1 null value: params.logo." and you get:
baseURL = "https://kitchen-notes.example/"
title = "Kitchen Notes"
languageCode = "en-gb"
[params]
description = "Bread, soup and weeknight dinners"
mainSections = ["posts"]
[[menus.main]]
name = "Posts"
pageRef = "/posts"
weight = 1
[[menus.main]]
name = "About"
pageRef = "/about"
weight = 2
The nested object became a [params] table, the plain array stayed inline, and the array of menu objects became two [[menus.main]] blocks. The download is named config.toml, so rename it to hugo.toml before you drop it into the project. The top level has to be a JSON object, because a TOML document is always a table. Date-like strings stay quoted strings, since JSON has no date type.
Why do uploaded images return 403 Forbidden?
After hugo builds the site into public/, you upload that folder to the host over SFTP. Sometimes the pages load and the photos don't, and the server log shows 403 errors. Often the files arrived with permissions that only let your own user read them.
Run ls -l on the server. If an image shows rw-------, type that into the Symbolic field of the Chmod Calculator and the Octal field changes to 600: owner can read and write, nobody else can do anything. The web server runs as a different user, so it can't read the file.
Click 644 in the Common permissions list, described there as "Files: owner can edit, everyone can read". The symbolic form becomes rw-r--r--. Type images/sourdough-16x9.jpg into File or folder and copy chmod 644 images/sourdough-16x9.jpg. Folders need 755 (rwxr-xr-x), because on a folder execute means the server may enter it. The calculator writes the command for one path. To fix the whole site at once, run the usual shell versions from the site folder on the server: find . -type f -exec chmod 644 {} + for files and find . -type d -exec chmod 755 {} + for folders. Skip 777, which the tool's list marks "Everyone can do everything โ avoid on servers".
How do you keep the post marked as a dated article?
WordPress SEO plugins often added Article structured data for you. A Hugo theme may or may not, so view the source of the built page and check. If it's missing, open the Article Schema Generator. Type starts on BlogPosting (blog post), which is right for a food blog.
Fill in Headline with "Sourdough on a Tuesday", Page URL with the new address and one line in Image URLs (one per line). Copy 2019-03-12 08:15:00 from the export into Date published (ISO 8601) and you get an error, because ISO 8601 needs a T between date and time and the tool rejects other formats. Enter 2019-03-12, or 2019-03-12T08:15:00+00:00 if you know the time zone. Put today's date in Date modified (ISO 8601) if you edited the post during the move. You get a warning if the modified date is earlier than the published one.
With Wrap in a <script> tag ticked, the output is ready to paste into the page template, and the download is named article-schema.html. Fields you leave empty are left out of the JSON-LD.
FAQ
Can the XML Formatter open a big WordPress export?
It formats whatever you paste, and nothing is uploaded. A very large export can make the browser slow to paste and format, so it's often easier to copy out a few <item> blocks and format just those.
Why are there three spaces after each dash in the Markdown lists?
That's how Turndown writes list items: the dash, then spaces to line the text up. Markdown renderers, Hugo's included, read it as a normal bullet list, so you can leave it or replace it with a single space.
Does the JSON to TOML Converter turn dates into TOML dates?
No. JSON has no date type, so a string such as "2019-03-12" stays a quoted string in the TOML. Remove the quotes by hand if your setting needs a real TOML date.
Should I use 644 or 755 for the files Hugo builds?
Use 644 for HTML, CSS and image files and 755 for folders. 755 on a plain file also lets everyone execute it, which a web page never needs.
The other converters and SEO helpers used here are in Developer Tools.
