Every WordPress to Webflow move I do hits the same wall at the same point. The design is built, the CMS collection is ready, and then someone exports the blog with Tools > Export and hands me an XML file. Webflow's CSV import doesn't take XML.
Export plugins work, but I got tired of clicking through settings on every client site. So now I skip the export and pull the posts straight from the WordPress REST API with a small Node script. It writes a CSV that Webflow's importer accepts on the first try, most of the time.
Here's the script and the handful of things that make it work.
What Webflow wants from the CSV
Webflow's help docs are specific, and each rule shaped the script:
- The file can be up to 4 MB. A blog with a few hundred long posts goes over that, so the script splits the output.
- The Name and Slug fields need fewer than 256 characters.
- Rich text accepts HTML, but Webflow strips elements, classes and attributes it doesn't support.
- Image fields need a direct URL that ends in an image extension. Those images don't get responsive variants, so it's worth pointing at a resized version, not the 5000px original.
- Reference and multi-reference fields take plain text (multi-reference separated by semicolons). Webflow turns the value into a slug and matches it. If the referenced item has a custom slug, you have to put the slug in the CSV.
That last one bites people. A WordPress category called "News & Updates" often has the slug news. Webflow would look for news-updates and find nothing. So the script exports term slugs, not names, and you import your categories with those same slugs first.
The script
// wp-to-webflow.mjs (Node 18+)
import { writeFileSync } from 'node:fs';
const SITE = 'https://example.com'; // the WordPress site
const MAX_BYTES = 3.8 * 1024 * 1024; // stay under Webflow's 4 MB
const FIELDS = [
'slug', 'date_gmt', 'title', 'excerpt', 'content',
'yoast_head_json', '_links', '_embedded',
].join(',');
async function getAllPosts() {
const posts = [];
let page = 1;
let totalPages = 1;
do {
const url = `${SITE}/wp-json/wp/v2/posts?per_page=100&page=${page}` +
`&_embed=author,wp:featuredmedia,wp:term&_fields=${FIELDS}`;
const res = await fetch(url);
if (!res.ok) throw new Error(`HTTP ${res.status} on page ${page}`);
totalPages = Number(res.headers.get('X-WP-TotalPages')) || 1;
posts.push(...(await res.json()));
page++;
} while (page <= totalPages);
return posts;
}
const decode = (s = '') => s
.replace(/&#(\d+);/g, (_, n) => String.fromCodePoint(Number(n)))
.replace(/&#x([0-9a-f]+);/gi, (_, h) => String.fromCodePoint(parseInt(h, 16)))
.replace(/&(quot|lt|gt|nbsp|hellip|amp);/g, (_, e) =>
({ quot: '"', lt: '<', gt: '>', nbsp: ' ', hellip: '…', amp: '&' })[e]);
const stripTags = (html = '') => decode(html.replace(/<[^>]+>/g, '')).trim();
// Webflow wants a direct URL that ends in the image extension
function importableImage(url = '') {
const clean = url.split('?')[0];
return /\.(jpe?g|png|gif|webp)$/i.test(clean) ? clean : '';
}
function cleanContent(html = '') {
return html
.replace(/\[\/?[a-z_-]+[^\]]*\]/gi, '') // shortcodes
.replace(/\sstyle="[^"]*"/gi, '') // inline styles
.replace(/<p>(\s| |<br\s*\/?>)*<\/p>/gi, '') // empty paragraphs
.trim();
}
function toRow(post) {
const emb = post._embedded ?? {};
const media = emb['wp:featuredmedia']?.[0];
const sized = media?.media_details?.sizes?.large?.source_url;
const terms = (emb['wp:term'] ?? []).flat();
const slugsFor = (tax) =>
terms.filter((t) => t.taxonomy === tax).map((t) => t.slug).join('; ');
const yoast = post.yoast_head_json ?? {};
return {
Name: decode(post.title?.rendered),
Slug: post.slug,
'Publish Date': post.date_gmt ? `${post.date_gmt}Z` : '',
Excerpt: stripTags(post.excerpt?.rendered).replace(/\s*\[…\]$/, ''),
Body: cleanContent(post.content?.rendered),
'Featured Image': importableImage(sized ?? media?.source_url),
'Featured Image Alt': media?.alt_text ?? '',
Author: emb.author?.[0]?.name ?? '',
Categories: slugsFor('category'),
Tags: slugsFor('post_tag'),
'SEO Title': decode(yoast.title ?? ''),
'Meta Description': decode(yoast.description ?? ''),
};
}
const cell = (v) => `"${String(v ?? '').replace(/"/g, '""')}"`;
function writeCsvFiles(rows) {
const headers = Object.keys(rows[0]);
const headerLine = headers.map(cell).join(',') + '\n';
let file = 1;
let chunk = headerLine;
for (const row of rows) {
const line = headers.map((h) => cell(row[h])).join(',') + '\n';
if (Buffer.byteLength(chunk + line) > MAX_BYTES && chunk !== headerLine) {
writeFileSync(`posts-${file++}.csv`, chunk);
chunk = headerLine;
}
chunk += line;
}
writeFileSync(`posts-${file}.csv`, chunk);
console.log(`Wrote ${rows.length} posts into ${file} file(s)`);
}
const posts = await getAllPosts();
const rows = posts.map(toRow);
for (const r of rows) {
if (r.Name.length >= 256) console.warn(`Name too long: ${r.Slug}`);
if (r.Body.includes(`${SITE}/wp-content/uploads`)) {
console.warn(`Inline images still on WordPress: ${r.Slug}`);
}
}
writeCsvFiles(rows);
Run it with node wp-to-webflow.mjs.
The parts worth explaining
_fields plus _embed. Asking for only the fields you need keeps each page of 100 posts small. The catch, which is in the REST API docs but easy to miss: when you combine the two, _links and _embedded have to be in the _fields list, or the embedded author, image and terms vanish.
SEO fields. If the site runs Yoast, every post comes back with a yoast_head_json object that has title and description in it. No database export needed. Those strings can contain HTML entities, which is why everything goes through decode(). If the site uses a different SEO plugin, those two columns come out empty and you'll need that plugin's own export.
The image size. media_details.sizes.large is the resized copy WordPress already made. Since Webflow won't build responsive variants for CSV-imported images, starting from the large size instead of the original saves you a heavy CMS template.
The image URL. I found this one by testing the script on a big public WordPress blog. Sites running Jetpack serve images through its CDN, and the REST API hands back URLs like i0.wp.com/.../hero.png?fit=1024%2C576&ssl=1. Close to half the featured images on that blog looked like that. Webflow wants the URL to end in the file extension, so importableImage() drops the query string. The downside is you get the full-size file again from the CDN, so on Jetpack sites check the sizes before import.
The warnings. The inline image check is the one that matters. Images inside the post body still load from the old server after import. The day WordPress gets switched off, they break. The script tells you which posts to fix before launch.
Import order in Webflow
- Import Categories and Tags first, using the WordPress slugs as the Slug column.
- Import Authors the same way. The script exports author names, so make sure the Author item slugs match the slugified names.
- Import the posts CSV. If your headers match your field names, Webflow maps them on its own.
- Say yes to the pre-import backup Webflow offers.
- Open ten posts on the live template before you trust any of it.
If a required reference doesn't match, Webflow imports that row as a draft with the field blank. So "all imported" on the success screen doesn't mean everything came through.
What it doesn't do
It won't fix page-builder markup. If the old posts were built in Elementor or Divi, the content is a pile of nested divs, and a regex isn't the right tool. It also doesn't handle custom post types; change posts in the URL to the type's REST base if you need those.
For the field planning side (what to keep, what to drop, how to map it to a collection), I wrote up the whole process here: How to import WordPress posts into the Webflow CMS.
Top comments (0)