All posts
Platform migrations

WordPress to Sanity or Payload: Going Headless the Right Way

WordPress to Sanity migration, step by step: turn Gutenberg HTML into structured blocks for Sanity or Payload, keep your URLs, and train editors before launch.

By Mehdi Hassan7 min read

The short answer

A WordPress to Sanity migration moves your posts and pages out of WordPress HTML into structured content. You export through the REST API or WXR file, parse Gutenberg blocks into Portable Text (or Lexical for Payload), re-host media, rebuild the front end in Next.js, redirect old URLs and train editors on the new block-based workflow.

Key takeaways

  • Use the WordPress REST API over the XML export when you can: it returns cleaner, typed data.
  • Gutenberg stores blocks as HTML with comment markers, which lets a script map them to structured blocks.
  • Shortcodes and page-builder markup are the slowest part; budget for manual fixes on key pages.
  • WordPress date and category URLs need a full redirect map before you switch DNS.
  • Editors need a short training plan, or they'll paste HTML back in and recreate the old mess.

Part of Headless CMS Migration: How to Move Between Contentful, Sanity, Payload and Strapi

Going headless from WordPress is one of the most common moves we're asked about, and one of the most often rushed. The risk isn't the export; it's ending up with your old HTML stuffed into a new CMS. This guide walks through the transform that turns WordPress content into real structured blocks, for Sanity or Payload, and the editor training that makes it stick. For the wider picture of moving between headless platforms, see our headless CMS migration guide.

What does a WordPress to Sanity migration involve?

A WordPress to Sanity migration involves four jobs: designing a content model, transforming WordPress HTML into structured blocks, rebuilding the front end, and protecting your URLs. WordPress renders pages on its own server; Sanity or Payload only store content, so a Next.js front end has to be built to display it.

That last point surprises people. Leaving WordPress for a headless CMS is not a content move alone; it's a new website build plus a content move. If you're new to the idea, our explainer on what a headless CMS is covers the basics without jargon. Typical ranges we see quoted for WordPress to headless Next.js projects run from about £13,000 to £30,000 over 6 to 12 weeks, and they vary a lot with the size of the site and how messy the content is.

Sanity or Payload?

Both work well as a WordPress replacement. Sanity is hosted and stores rich text as Portable Text. Payload is open source, runs inside your Next.js app and stores rich text as Lexical JSON. The transform steps below are the same for both; only the output format changes. Our comparison of Contentful, Sanity, Payload and Strapi helps you choose.

How do you export WordPress content for a headless CMS?

You export WordPress content either through the REST API, which returns posts, pages, media, categories and users as JSON, or through the Tools, Export screen, which produces a WXR XML file. We prefer the REST API because it gives typed fields, IDs and links, and it can include custom post types and custom fields when they're exposed.

Method

Best for

Limitations

REST API (wp-json)

Most sites; scripted, repeatable exports

Custom fields must be exposed to the API

WXR XML export

Locked-down hosts, quick snapshots

Messy XML; media is referenced, not included

Direct database dump

Very large or heavily customised sites

Needs a developer; raw serialized data

Migration plugins

Simple blogs

Output often still unstructured HTML

Whichever you choose, pull SEO metadata too. If you use an SEO plugin, titles and descriptions live in its own fields, not the post title. Our guide on how to export a WordPress site's content covers each method, including media and custom fields.

How do you turn Gutenberg HTML into structured blocks?

You turn Gutenberg HTML into structured blocks by parsing the block comment markers WordPress saves around each block, then mapping each block type to a block in your new schema. Gutenberg saves a paragraph as HTML wrapped in a wp:paragraph comment, an image as wp:image with its attachment ID, and so on, which gives a script something reliable to read.

Gutenberg block

Sanity (Portable Text)

Payload (Lexical)

wp:paragraph

block, style normal

paragraph node

wp:heading

block, style h2 to h4

heading node

wp:list

blocks with listItem

list and listitem nodes

wp:image

image object with asset reference

upload node to a media doc

wp:quote

block, style blockquote

quote node

wp:embed (YouTube etc.)

custom embed object

custom block

wp:html or shortcodes

manual review

manual review

For the HTML inside each block, Sanity's block tools package can convert HTML into Portable Text, and Payload's Lexical package includes an HTML-to-Lexical converter. Classic-editor posts, written before Gutenberg, have no block markers, so they go straight through the HTML converter with stricter clean-up rules.

Hypothetical example: a post with a shortcode and an inline style

For example, suppose a 2019 post contains a gallery shortcode, a paragraph with inline color styles and a raw HTML table.

The script strips the inline styles, because the new design system controls color. The gallery shortcode is matched by name and replaced with a gallery block whose images are looked up by attachment ID. The raw HTML table has no clean equivalent, so the script flags the post for manual review and logs its URL. At the end you get a short list of posts a person needs to fix, instead of hundreds of silently broken pages.

What are the steps to migrate WordPress content to Sanity or Payload?

The steps are: audit, model, export, transform, import, rebuild, redirect, then train. Run the transform repeatedly on a copy until the error log is short, and only freeze WordPress for the final import.

  1. Audit the content

    Decide what to keep, merge or drop. Old tag archives and thin posts rarely deserve a place in the new CMS.

  2. Design the content model

    Define posts, pages, authors, categories and the blocks editors may use. Our content modeling guide shows how to structure collections for a SaaS site.

  3. Export and re-host media

    Download every attachment, upload it to the new CMS, and keep a map from WordPress attachment IDs and URLs to new asset IDs.

  4. Transform posts

    Parse Gutenberg blocks, convert HTML to structured blocks, swap image URLs for asset references and rewrite internal links.

  5. Import and spot-check

    Import in dependency order: authors and categories first. Compare twenty key posts side by side with the live site.

  6. Rebuild the front end

    Build the Next.js templates against real imported content, not dummy text.

  7. Map every URL

    Export all live URLs, including date-based permalinks and category archives, and redirect each one that changes.

  8. Train editors and cut over

    Run the training sessions below, freeze WordPress, do a final import, then switch DNS.

How do you train editors after moving off WordPress?

You train editors with short, task-based sessions on real content, before launch, followed by a written cheat sheet. Editors coming from WordPress are used to a page that looks like the final site; a structured editor feels different, and without training they work around it.

  1. Session one, the model: what each document type is for, and why there's no free-form HTML box.
  2. Session two, everyday tasks: write and publish a post, add an image with alt text, add a link to another post.
  3. Session three, preview and SEO fields: use live preview, fill in the SEO title and description, schedule a post.
  4. First two weeks: a shared channel for questions, and a review of the first few posts each editor publishes.

If editors keep asking for a feature, that's useful feedback on the model, not a training failure. Adjust the schema early, while there's little content to update.

How do you protect SEO when leaving WordPress?

You protect SEO by keeping URLs where possible, redirecting every URL that changes, and carrying over titles, descriptions and canonical tags exactly. WordPress sites often have date-based permalinks, category paths and attachment pages that are easy to forget, and those are where traffic usually leaks after a move.

Crawl the old site before you start and save the URL list. After the import, crawl the staging site and compare the two: every old URL should return the same page or a single 301 redirect, never a chain or a 404. For a broader process that applies to any platform, see our guide to CMS content migration. If you later decide Sanity isn't right, the same principles apply to a Sanity to Payload migration.

Frequently asked questions

Can I keep WordPress as the CMS and only change the front end?
Yes. You can use WordPress headlessly through its REST API and build a Next.js front end on top. It avoids a content migration, but you keep WordPress hosting, plugin updates and security patching. It's a reasonable step if your editors love WordPress and the main problem is design or speed, not the editing experience.
What happens to my WordPress plugins?
Plugins don't come with you, because they run inside WordPress. Each one needs a replacement: forms move to a form service or your CRM, SEO fields move into the CMS schema, and analytics moves into the new front end. List every active plugin early and decide what replaces it, or drop it.
Do WordPress comments migrate to Sanity?
Not by default. Sanity and Payload don't include a comments system. You can import old comments into a custom document type and display them as read-only, move to a third-party comments service, or drop comments. Many marketing blogs choose to drop them, but check whether old comments carry useful content first.
Is Sanity or Payload easier for former WordPress editors?
Both feel different from WordPress at first. Sanity's Studio is polished and its visual editing helps people who like to see the page. Payload's admin is clean and familiar to anyone who has used a form-based CMS. With live preview set up and a short training plan, editors adapt to either within a few weeks.
How do I handle WooCommerce if I leave WordPress?
WooCommerce is a store, not just content, so it's a separate decision. Moving a store means choosing a new commerce platform for products, checkout and orders, not just a CMS. Many teams move the marketing site to a headless CMS first and leave the store where it is until they're ready for that larger project.

· CEO & Design Director

Copywriter, designer and developer, and founder of Designify Studio. Over five years, 60+ projects across 14+ industries, for startups that have raised $300M+.

Want this done for you? Website, $8,000.

A multi-page marketing site, written and designed by us, developed in Next.js and animated. $8,000, one-time, up to 6 pages. Book a free 30-minute call to see if it fits.

Schedule Call