Migrating Over 3,000 WordPress Posts to BearBlog with Python
If you've ever exported a WordPress site and ended up with a folder full of markdown files, you know the feeling: the content is there, but it's not quite ready for anywhere else. The metadata is in the wrong shape, the image links are all broken, and the idea of fixing things post by post is enough to make you close the laptop and walk away.
For the past several months, I've been doing this process manually of editing each file and putting them up as I completed each of them.
Then I got the idea of asking Claude Code if it could help me automate this process somehow. Enter Python. :🐍 The script it created was built to solve exactly that problem at scale. In my case, over 3,000 posts spanning nearly 20 years.
What it does
The script takes a folder of WordPress-exported markdown files and batch-converts them into notes that are ready for both Obsidian Publish and BearBlog.
For each file it:
🤖 PLEASE BE ADVISED CLAUDE WROTE THESE BULLET POINTS BECAUSE I HAVE A VERY POOR UNDERSTANDING OF PYTHON.
- Parses the existing YAML front matter from the WordPress export (title, date, categories) and rewrites it into a clean Obsidian-compatible front matter block with the fields I actually use:
title,date,published_date,tags, andpublish. - Inserts a BearBlog YAML code block directly below the front matter. BearBlog uses a fenced
```yaml ```block inside the note body to read post metadata, so this gets generated automatically from the same source data. - Strips all broken image references — since my WordPress media library didn't come along for the ride, every image link in the exported markdown was dead. The script removes all markdown image syntax entirely, including the nested linked-thumbnail style WordPress commonly exports (
[](full.jpg)). - Strips WordPress shortcodes like
[gallery link="file" columns="1" orderby="rand"]that have no meaning outside of WordPress. - Appends a reply-by-email footer to every post — a small HTML block with a mailto link, consistent with BearBlog's indie web spirit.
- Flags empty posts — if a note has no body content left after all the cleaning, it gets tagged
needs-contentin its Obsidian front matter so it's easy to surface and review later. - Writes a
_conversion_log.mdto the folder on completion, listing every file processed with ✅, ⚠️, or ❌ status markers. Being a.mdfile means it shows up right in Obsidian's file explorer alongside the notes.
How it looks in practice on Linux Mint
The script runs from the command line (Terminator or Ghostty for me) and takes a single folder path as its argument:
python3 wp_to_bearblog.py /path/to/your/posts/2012/07
It processes every .md file in that folder in place and is designed to be run one month at a time, which maps naturally to how WordPress structures its export folders.
If you've got a dusty WordPress export sitting on a hard drive somewhere, hopefully this gives you a nudge to dig it out. Old writing deserves a second life. ■