- Python 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| docs/images | ||
| tests | ||
| .gitignore | ||
| CHANGELOG.md | ||
| LICENSE | ||
| README.md | ||
| requirements.txt | ||
| scan_wp_export.py | ||
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) |
|---|---|
![]() |
![]() |
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).
-
Get the export. In WordPress, go to Tools → Export → All content → Download Export File. Save it in this folder as
export.xml. -
Get the photos. Copy the site's
wp-content/uploadsfolder into this folder asuploads(with your host's File Manager, an FTP program, or by downloading a zip of it and unzipping here). -
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.txtThe
.venvfolder keeps them separate from the rest of your computer (current Linux won't install them any other way). -
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 -
Convert:
.venv/bin/python scan_wp_export.py export.xml --host www.example.org \ --copy-images --write-markdown --fetch-map-tracks --number-pagesOn Windows use
.venv\Scripts\pythonand put it all on one line without the\. -
Read the report it prints (see below), then copy the contents of the new
grav_pagesfolder intouser/pageson your Grav site and clear Grav's cache (Admin2's Clear cache, orbin/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.

The report
It prints, in order:
- 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).
- Posts that need a look: shortcodes and blocks Grav doesn't understand, and images or links still pointing at the old site.
- Images copied, and any it couldn't find in
uploads. - Pages written.
- 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
bcryptdidn'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.
- 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
- 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
.gpxand.kmlfiles from page folders and Route Map adds its own download link. Remove the old links once WordPress is gone. - With
--copy-imagesbut 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,-3on the folder name.
For developers
scan_wp_export.pyis the whole tool.requirements.txtlistsmarkdownify(HTML to Markdown) andbcrypt(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.

