News

Migrate from WordPress to SanityCMS

WordPress, SanityCMS, Migration, Guide

Written by: 

Hex Digital

Unlock the future of editing, with click-to-edit functionality, powerful collaboration, live previews, and all the rest. Step out of the past with a CMS that will keep you impressed.

And if the below seems like a lot of work, you’d be right. Thankfully, Hex can do it all for you, just send us a message.

The Limitations of WordPress

WordPress has long been a reliable workhorse, but it comes with some serious limitations. It's a single-player CMS in a world where digital teams need collaboration. Editing a post locks the document for everyone else, real-time previews are non-existent, and team visibility is minimal at best. WordPress can feel like working on an isolated island—outdated and, dare I say, frustrating.

And while WordPress is "free," it often comes with hidden costs. From plugin licenses to continuous security and maintenance requirements, not to mention the time spent just trying to boost performance, WordPress can be resource-intensive. Plus, if your digital strategy involves more than just a website—say, a mobile app or an IoT experience—using the WordPress REST API might technically work, but you'll be wrestling with content that wasn’t designed for portability or reuse.

Sound familiar? Enter SanityCMS.

Sanity brings a new era of content management, one that’s powerful and adaptable for every stakeholder. Editors get real-time updates, developers get streamlined content for performance, and the business gets the best of both worlds—fresh content served fast.

Why SanityCMS is a Game-Changer

SanityCMS comes packed with features that transform content management into a seamless, enjoyable experience:

Editorial Experience

Multiplayer editing and collaboration is something we expect from our tools these days. Tools like Google docs and Notion, with no document locking, live-as-you-type previews, presence indicators, comments and tasks, etc.

Your CMS is supposed to be the home of your content, so why settle for any less here? It needs to be powerful and work for you, and that’s exactly what SanityCMS does.

Real-Time Collaboration
Collaborate like never before with multiple team members editing, updating, and commenting in real time. No more document locks.

Live Previews
What you see is truly what you get. Preview updates in real time without breaking your flow.

Click-to-Edit Functionality
Tired of switching tabs and searching for fields? Just click on content and start editing right away.

In-CMS Comments and Task Management
Keep feedback, revisions, and tasks exactly where they belong—alongside your content.

Scheduled Publishing
Prepare content ahead of time and publish it when it counts.

Version History and Rollback
Mistakes happen. Sanity’s version history allows you to roll back to any point in time, easily.

Marketing Experience

And let’s not forget the goal of our websites. If your CMS isn’t serving that purpose, it’s holding you back.

Customisable A/B Testing
Run A/B tests on your terms, allowing you to refine content for optimal impact without compromise.

Unrestricted Personalisation
Personalise freely with a flexible front-end and structured content. No limitations, just possibilities.

Analytics Integrations
Sync easily with analytics, giving marketers a complete understanding of user behavior and campaign performance.

Developer Velocity

Developers get a significant boost with Sanity’s developer-first approach. What might take a week to implement in WordPress can often be achieved in a single day with Sanity. Increased developer velocity means a faster go-to-market time, fewer technical roadblocks, and a genuinely more enjoyable development experience.

Cost Efficiency

WordPress, especially when overloaded with plugins, demands constant attention. Regular updates, security patches, performance fixes—it’s a lot. With Sanity, a managed service model alleviates much of this, spreading the operational burden across hundreds of thousands of projects. The outcome? Your team is free to focus on what matters: content and user experience.

When it comes time for the next website refresh or rebrand project, you’ll be pleasantly surprised that there’s no longer a content migration to do. Just swap out the frontend, re-using all of your content as it is to power the new experience. Talk about a huge cost saving.

Migration to SanityCMS: What to Expect

Migrating from WordPress to Sanity isn’t a simple plug-and-play process. WordPress stores more than just content; it’s layered with HTML, JavaScript, and custom styling. Each implementation is unique, which means a one-size-fits-nobody migration script just won’t work. That’s where our expertise comes in.

We’ve developed a robust foundation of migration scripts that can be tailored to your specific WordPress setup, simplifying the process of extracting content while stripping out unnecessary baggage. Whether you’re using plugins or have custom-built features, Sanity’s flexibility means everything you’ve built can be mirrored—and enhanced—in your new CMS.

SanityCMS doesn’t limit you to cookie-cutter functionality; it offers customisability that exceeds WordPress. With Sanity, you’re moving to a platform that grows and evolves with your needs, not against them.

The Migration has three key steps

Understand the content you want to migrate

First things first, take stock of what you have in your WordPress site. There’s a lot of variety of how content can be stored, such as:

  • Custom fields and post types added by plugins or themes
  • Content stored in the WordPress database in unexpected ways
  • Multilingual content using various plugins and approaches
  • Media and files are stored in multiple places, not always as WordPress attachments
  • Inconsistent use of Gutenberg blocks, the Classic editor, or page builder plugins

You’ll want to write out what data you want to migrate from this list.

At the same time, you can consider dropping legacy or under-performing content that you don’t want to take with you.

Map WordPress content to Sanity data schemas

Once you’ve identified the data you want to keep, the next step is to map it to Sanity.

You’ll do this by creating data schemas in Sanity to capture the appropriate data from WordPress. This could include a schema for Posts, Pages, Authors, Categories, and more.

Initially, we’ll map content from WordPress to Sanity in a 1:1 relationship, to ease migration. Later on you’ll want to extract and re-structure your exported WordPress content into a more refined content model. This is a super power of Sanity.

WordPress stores a document’s “author” as a “user” in the database. Sanity keeps these separate, treating authors as an editorial concern, and allowing you to extend the author model as needed and have authors that aren’t necessarily CMS users. It also enables multi-authoring of content. So you’ll want to create an “author” in Sanity for each “user” in WordPress.

At this point, you’ll have a Sanity studio with a schema ready to import data from WordPress into.

Exporting from WordPress and importing to Sanity

To handle the actual migration, you’ll use the WordPress REST API. This may need to be enabled if it is currently blocked by your settings or a security plugin. You can confirm it’s available by visiting your site, at: https://<your-domain-name>/wp-json/wp/v2.

When you’re ready, you’ll need to write a migration script using Sanity. You can generate the file to write this script into using npx sanity@latest migration create "WordPress Import".

The script itself will need to fetch all content from WordPress, and map it to the appropriate Sanity schemas. It will then need to transform the content from WordPress to the appropriate fields in Sanity. You can use helpers like wp-types, html-entities, p-limit, @sanity/block-tools, jsdom, and @wordpress/block-serialization-default-parser to help with this transformation.

Don’t forget to relate documents to each other, such as authors and taxonomies to posts. This can be handled by querying Sanity for the corresponding documents by name, and then adding the document ID to the reference fields.

All Sanity documents have a _createdAt and _updatedAt field for timestamping. However, if these fields have editorial meaning, such as when an article was published or updated, we recommended using separate fields for this. So ensure you’re importing dates into separate fields, such as publishedAt and updatedAt.

Assets are another case where care is required. Assets can take a while to upload, especially if there’s a lot of them, so we want to make sure we’re uploading them in batches, not one at a time. You can use p-limit to manage this asynchronous upload of assets. With this, you can upload images to Sanity as they’re found, in a separate asynchronous process, and attach them to your content.

When uploading assets, you can add metadata for where the asset came from. This allows the re-running of this script to be more efficient, by avoiding re-uploading images that have already been migrated.

Documents in WordPress are often stored in HTML. This provides little flexibility in how that document will appear on your frontend, and makes it difficult to use across multiple mediums, like multiple websites, mobile apps, IoT devices, and more.

Instead, this HTML should be converted to Portable Text Content. If you’re using ACF, Gutenberg, or the Classic Editor, this process isn’t too bad, and just requires care when writing to map to the correct blocks.

If you’re using a visual builder like Elementor or Divi, this process is exponentially harder, and may require much manual intervention, as these platforms lock your content to their code structure. The good news about migrating to Sanity is that you won’t ever have to deal with this content lock-in again.

Once you’ve finished importing and converting your content to Portable Text, you can think about taking the opportunity to restructure it.

Content is WordPress is presentation-focused—how it will display on the frontend is baked in to the content itself, via HTML, styles, and more. Sanity, on the other hand, is structured around the content itself, and its semantic meaning.

Often pages are composed of content from multiple sources, such as “staff”, “locations”, “offices”, “awards”, “case studies”, and more. This content can be broken down into its pieces, then re-composed on the frontend to build up pages. It can then also be used for myriad different uses in the future, as needed.

A great place to start is anywhere a page template is used in WordPress. Often these constitute a mix between content and presentation, and separating the two will clear you from the “pages lock-in” thinking, and free you of ever needing to migrate your content again.

Once you’ve migrated to Sanity, you’re now ready for any re-brand, re-design, or re-build the future will throw at you, without any more content migrations. What a time to be alive.

---

Switching to SanityCMS isn’t just a platform upgrade; it’s a reimagining of what your CMS can be. Ready to leave the frustrations of WordPress behind and unlock a new level of content management? Let’s take that first step.

Enjoyed what you read?

Want to chat about the above content? Email us at hello@hexdigital.com

Or send us a message with the form opposite, and we’ll be in touch within 24 hours.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.