Standalone tool: convert WordPress content to Grav
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-15 12:31:48 +00:00
docs/images 1.1.0: keep protected posts protected, stop image name clashes, safer paths and downloads 2026-10-11 12:11:01 +00:00
tests 1.3.0: folder order as documented, full page count, no blank-line runs; README rewritten for first-time users 2026-11-15 11:57:46 +00:00
.gitignore 1.3.0: folder order as documented, full page count, no blank-line runs; README rewritten for first-time users 2026-11-15 11:57:46 +00:00
CHANGELOG.md 1.3.1: MIT licence 2026-11-15 12:31:48 +00:00
LICENSE 1.3.1: MIT licence 2026-11-15 12:31:48 +00:00
README.md 1.3.1: MIT licence 2026-11-15 12:31:48 +00:00
requirements.txt 1.1.0: keep protected posts protected, stop image name clashes, safer paths and downloads 2026-10-11 12:11:01 +00:00
scan_wp_export.py 1.3.1: MIT licence 2026-11-15 12:31:48 +00:00

WordPress to Grav

Vision: move a WordPress site to Grav without losing anything: every post and page, with its photos, its route maps and its password, in a folder tree that goes straight into Grav, plus a plain report of anything a person still needs to look at. It runs on your own computer, so nothing is installed on the web host.

WordPress to Grav (scan_wp_export.py) reads the export file WordPress makes and writes one Grav page folder per post or page.

The post in WordPress The converted page in Grav (Anti-Asteroid theme, Route Map plugin)
A WordPress post with two photos The same post in Grav, with both photos and a route map

Both photos are called photo.jpg in WordPress (uploaded in different months); in Grav the second becomes photo-2.jpg. The map shortcode was replaced by the track file, which the Route Map plugin draws.

Quick start

You need Python 3.10 or later (python.org; on Windows tick Add Python to PATH when installing).

  1. Get the export. In WordPress, go to Tools → Export → All content → Download Export File. Save it in this folder as export.xml.

  2. Get the photos. Copy the site's wp-content/uploads folder into this folder as uploads (with your host's File Manager, an FTP program, or by downloading a zip of it and unzipping here).

  3. Install the two helpers it uses, once. In a terminal opened in this folder:

    python3 -m venv .venv
    .venv/bin/pip install -r requirements.txt          # Windows: .venv\Scripts\pip install -r requirements.txt
    

    The .venv folder keeps them separate from the rest of your computer (current Linux won't install them any other way).

  4. See what it finds, without writing anything. Use your old site's address:

    .venv/bin/python scan_wp_export.py export.xml --host www.example.org
    
  5. Convert:

    .venv/bin/python scan_wp_export.py export.xml --host www.example.org \
        --copy-images --write-markdown --fetch-map-tracks --number-pages
    

    On Windows use .venv\Scripts\python and put it all on one line without the \.

  6. Read the report it prints (see below), then copy the contents of the new grav_pages folder into user/pages on your Grav site and clear Grav's cache (Admin2's Clear cache, or bin/grav clearcache).

What it does

Option What it does
(none) Only reports. Nothing is written
--host Your old site's address, so it can recognise its own images and links. www.example.org and example.org count as the same site, as do links like /wp-content/uploads/…
--write-markdown Writes each post and page as a Grav page: title, date, published or not, categories and tags, and the content in Markdown
--copy-images Copies the photos each post shows (and links to) from uploads into its page folder. Two different files with the same name become photo.jpg and photo-2.jpg, and the page is changed to match. Needs --host
--fetch-map-tracks Downloads every .gpx or .kml route file a page uses into its folder and removes the map shortcodes (WP OSM, Flexible Maps, or any shortcode naming a route file), so Grav's Route Map plugin draws the route. Ordinary links to route files are kept. Files over 25 MB are skipped; only http and https. Needs --write-markdown and --host, and an internet connection. (Older name: --fetch-osm-tracks)
--number-pages Numbers the folders so Grav's menu follows the old site: 01.motorbikes/01.trips/01.2024. Pages given an order in WordPress come first, in that order, then everything else (posts, unordered pages) newest first
--number-width Minimum digits in those numbers (default 2)
--template Sets one Grav template for every page. Without it, posts have none, so Grav shows them as blog posts, and WordPress pages use Grav's plain default page
--page-filename The page file's name in each folder (default item.md)
--uploads-dir, --output-dir Where the photos are and where the pages go (defaults uploads and grav_pages, in the folder you run it from)
--version, --help The version, and this list

The result looks like this:

grav_pages/
  01.motorbikes/
    item.md
    01.trips/
      01.2024/
        item.md
  02.best-of-both/
    item.md
    photo.jpg
    photo-2.jpg
    route.gpx

And a converted page:

---
title: 'Best of both'
date: '2024-07-01 10:00:00'
published: true
taxonomy:
    category: ['Uncategorised']
---

Both photos, same file name, different months.

![May](photo.jpg)![June](photo-2.jpg)

The report

It prints, in order:

  1. How many posts and pages it read, and how many were empty (empty pages are kept: in WordPress they're often the parent of other pages, and Grav needs them for the menu).
  2. Posts that need a look: shortcodes and blocks Grav doesn't understand, and images or links still pointing at the old site.
  3. Images copied, and any it couldn't find in uploads.
  4. Pages written.
  5. Visibility: every page that wasn't public in WordPress. Check each one in Grav:
    • Password-protected posts get the same password for the Page Password plugin, stored as a secure hash. Without that plugin these pages are public in Grav, so install it before copying them to a live site. It also protects the page's subpages, which WordPress didn't. (If bcrypt didn't install, the password is written as plain text and the report says so: install it and run again, or open and save the page in Admin2.)
    • Drafts, private, pending and scheduled posts are written as unpublished, so Grav doesn't show them.
  6. Route files (.gpx, .kml): how many were downloaded, and any that failed.

Limits

  • Featured images, and images named only inside shortcodes, aren't copied.
  • Other shortcodes (such as [gallery]) are left as they are, for you to replace.
  • Categories and tags used as menu entries don't become pages.
  • Comments aren't converted.
  • Links to route files still point at the old site, because Grav doesn't serve .gpx and .kml files from page folders and Route Map adds its own download link. Remove the old links once WordPress is gone.
  • With --copy-images but not --write-markdown, photos are copied but there are no pages to update.
  • Two posts with the same address name under the same parent get -2, -3 on the folder name.

For developers

  • scan_wp_export.py is the whole tool. requirements.txt lists markdownify (HTML to Markdown) and bcrypt (password hashes; optional).
  • Tests: .venv/bin/python -m unittest discover -s tests -v. They build small exports on the fly and use a local web server for the downloads, so they need no network.

Version, licence and author

Version 1.3.1; see CHANGELOG.md. MIT licence (LICENSE). By Rawrso.me - David Hall.