The cleanest way to migrate WordPress to Next.js is to keep WordPress as a headless backend and rebuild only the frontend in Next.js, pulling content through the REST or GraphQL API and rendering it as static or incrementally-revalidated pages. You get React's speed and developer experience without throwing away the editor your team already knows. I've done this migration for client sites and my own, and the hard part is never the rendering — it's revalidation, caching, and redirects. This guide walks the whole thing, with the code and the gotchas.
What "migrating WordPress to Next.js" actually means

There are two very different projects hiding under the same sentence, and picking the wrong one wastes weeks.
The first is headless WordPress: WordPress stays alive as a content API and admin panel, and Next.js becomes the public-facing site. Editors keep using the WordPress dashboard; visitors never touch it. This is the pragmatic, reversible path most teams want.
The second is a full migration off WordPress: you export all content into a different store (Markdown files, a database, or a modern CMS like Sanity or Payload) and retire WordPress entirely. More work, more freedom, no PHP to maintain.
This guide covers both, but leads with headless — it's where most real migrations land.
Headless WordPress vs full migration: pick your scenario
The decision comes down to who edits the content and how attached you are to the WordPress ecosystem.
| Factor | Headless WordPress + Next.js | Full migration off WordPress |
|---|---|---|
| Editor experience | Unchanged — WP dashboard | New CMS to learn |
| Migration effort | Medium — rebuild frontend only | High — move all content + admin |
| Ongoing maintenance | Two systems (WP + Next) | One system |
| Plugin dependence | Keep what works via API | Must replace every plugin |
| Hosting cost | WP host + Next host | Next host only |
| Reversibility | Easy — WP still runs | Hard — WP is gone |
| Best for | Teams that love the WP editor | Devs who want WP fully gone |
My default recommendation: start headless. You ship the performance win fast, you keep the editorial workflow, and you can always finish the full migration later once the frontend is stable.
The benefits — why teams move to Next.js at all
This is the upside, stated honestly. Next.js earns the migration when these matter to you.
- Speed. Static and incrementally-rendered pages serve from a CDN edge, so you skip PHP execution and database queries on every request. Core Web Vitals usually jump.
- Developer experience. React components, TypeScript, a real build pipeline, and Git-based deploys beat wrangling PHP templates and plugin conflicts.
- Security surface. A static frontend has almost nothing to hack. No public WordPress login, no plugin CVEs exposed to visitors.
- Scalability. Traffic spikes hit a CDN, not your origin server. A viral post won't take the site down.
- Flexibility. You can mix WordPress content with data from other APIs, an e-commerce backend, or AI features — all in one React app.
The demerits — where this bites you
The part that makes the rest believable. I've hit every one of these.
- Complexity goes up, not down. You now run two systems (if headless) and a build pipeline. That's more moving parts than a single WordPress install.
- Preview and revalidation are genuinely hard. Editors expect to hit "Update" and see the change live. With static rendering, that's an engineering problem you must solve (covered in depth below).
- Plugins stop working on the frontend. Contact forms, related-posts widgets, page builders like Elementor — none of their frontend output survives. You rebuild that functionality in React.
- Gutenberg block rendering is fiddly. WordPress returns blocks as HTML; styling and hydrating them correctly in React takes real effort.
- Cost and skills. You need a React developer to maintain it. A non-technical owner who could edit a WordPress theme now can't.
Step 1: Expose WordPress as an API
WordPress ships with the REST API at /wp-json/wp/v2/ out of the box, but for a real migration I prefer GraphQL via the WPGraphQL plugin — you fetch exactly the fields you need in one request instead of stitching together REST calls.
Install these plugins on the WordPress side:
- WPGraphQL — adds a /graphql endpoint.
- WPGraphQL for Advanced Custom Fields — if you use ACF, this exposes those fields.
- A headless-friendly preview/redirect plugin if you need draft previews (more later).
Once WPGraphQL is active, you can query posts like this:
If you'd rather stay on REST, the equivalent endpoint is:
The _embed flag pulls in the featured image and author in one call, which saves you a follow-up request per post.
Step 2: Scaffold the Next.js app
Spin up a fresh Next.js project using the App Router — it's where Server Components, streaming, and the modern caching model live.
Store your WordPress endpoint in an environment variable so it's not hardcoded:
Step 3: Fetch and render content
Here's the core pattern in the App Router. A server component fetches WordPress data at build or request time and renders it. This example lists posts:
For individual posts, use a dynamic route with generateStaticParams so every post is pre-rendered at build time:
That dangerouslySetInnerHTML line is unavoidable — WordPress returns rendered HTML, and you inject it. The catch is that Gutenberg's block styles won't come along for free, which is the next problem.
Step 4: Handle Gutenberg blocks and styles
WordPress content arrives as a blob of HTML with WordPress-specific class names (wp-block-image, wp-block-quote, and so on). Three ways to deal with it, from least to most effort:
- Ship a stylesheet that mimics the core block CSS so the injected HTML looks right. Fastest, least flexible.
- Parse the HTML and swap key elements for React components — replace WordPress image tags with the Next.js Image component for automatic optimization. Use a library like html-react-parser.
- Query raw block data (WPGraphQL has block extensions) and render each block type with its own React component. Most work, most control, best result.
For most migrations I start with option one to get live, then upgrade hot paths (images, embeds, code blocks) to real components over time.
Step 5: Migrate images
Images are the silent time-sink. WordPress media lives in /wp-content/uploads/ and the URLs point at your WordPress origin. Two choices:
- Leave images on WordPress and reference them remotely. Add the WordPress domain to next.config.js so the Image component will optimize them:
- Or download every asset and move it to your Next.js host or an object store like Cloudflare R2 or S3, then rewrite the URLs. More work up front, but it cuts the dependency on the WordPress server for media.
The remote-pattern approach is the faster migration. Move media off WordPress only if you intend to fully retire it.
The hard part: revalidation, cache, and stale content
This is where migrations actually fail, so it gets the most space. The problem in one sentence: your pages are static, but your content changes — so how does an edit in WordPress reach the live site?
Why static content goes stale
When you statically render a post at build time, that HTML is frozen. An editor updates the post in WordPress, hits "Update," refreshes the live site — and sees the old version. Nothing is broken; the page is simply a cached snapshot. Every static-site migration runs into this, and "just rebuild the whole site on every edit" doesn't scale past a few hundred pages.
Option A: time-based revalidation (ISR)
The simplest fix is Incremental Static Regeneration — tell Next.js to re-fetch a page on a schedule. That's the next: { revalidate: 3600 } you saw earlier: serve the cached page, and at most once an hour regenerate it in the background.
The trade-off is bluntly a freshness-versus-load dial. A short interval means fresher content but more requests to WordPress. A long interval means edits take a while to appear. Time-based revalidation is fine for blogs where a one-hour delay is acceptable. It's not fine when an editor needs to fix a typo and see it instantly.
Option B: on-demand revalidation (the right answer)

The professional solution is to revalidate only the pages that changed, the moment they change. Next.js exposes revalidatePath and revalidateTag for this. You build a webhook in Next.js, then have WordPress call it whenever a post is saved.
The Next.js side — a route handler that purges a specific path:
The WordPress side — fire the webhook on every save. Drop this in your theme's functions.php or a small custom plugin:
Now an editor saves a post, WordPress pings Next.js, and only that page plus the index regenerate within seconds. This is the setup that makes a headless site feel as responsive as classic WordPress.
Using cache tags for related content
A single edit often touches more than one page — a post change should also refresh its category page, the homepage, and any "recent posts" list. Tag your fetches, then invalidate the tag:
Tags are cleaner than listing every path by hand. Use a broad tag for "anything that shows post lists" and specific paths for the post itself.
The layered cache problem nobody warns you about

Even with on-demand revalidation wired up perfectly, content can still look stale — because there are usually four caches between WordPress and the visitor, and you have to bust all of them:
- The WordPress object/page cache (plugins like W3 Total Cache or your host's cache) can serve the API a stale response.
- Next.js's own data cache and full-route cache.
- Your host's CDN cache (Vercel, Cloudflare) sitting in front of Next.js.
- The visitor's browser cache.
When an edit "won't show up," it's almost always one of these — most often the WordPress-side cache returning old API data, so your webhook regenerates a page from stale source. The fix is to exclude /graphql and /wp-json from any WordPress caching plugin, and set sane cache headers on the CDN. Debug from the source outward: check the raw API response first, then Next.js, then the CDN, then the browser.
Step 6: Preserve SEO — redirects, slugs, and metadata
A migration that loses your rankings is a failure no matter how fast the new site is. Protect three things:
- Keep URL structures identical. If WordPress used /blog/post-name, your Next.js routes must match exactly. Mismatched slugs mean 404s and lost link equity.
- Add 301 redirects for anything that does change. Map old URLs to new in next.config.js so search engines and backlinks follow:
- Port your metadata. Whatever Yoast or Rank Math generated (titles, descriptions, Open Graph, canonical tags) must be reproduced with the Next.js Metadata API:
Also regenerate your sitemap.xml and robots.txt on the Next.js side, and submit the new sitemap in Google Search Console the day you cut over. Watch the coverage report for a week.
Step 7: Deploy and cut over
Deploy the Next.js app (Vercel is the path of least resistance for Next.js; Netlify, Cloudflare Pages, or a self-hosted Node server all work). Keep WordPress running on a subdomain like cms.your-site.com or admin.your-site.com — it stays the backend, just no longer the public face.
The safe cutover sequence:
- Deploy Next.js to a staging URL and test every template against live WordPress data.
- Crawl the staging site (Screaming Frog) and diff URLs against the old site to catch missing pages.
- Move WordPress to a subdomain and point the API there.
- Switch DNS for the main domain to the Next.js host.
- Watch Search Console and server logs for 404s; add redirects for anything you missed.
Do the DNS switch during low traffic, and keep the old WordPress reachable on its subdomain so you can roll back instantly if something's wrong.
Full migration: leaving WordPress entirely
If the goal is to retire WordPress completely, the frontend work above is identical — the difference is where content lives afterward. The usual paths:
- Export to Markdown/MDX. Use a tool to convert WordPress posts to Markdown files committed to your repo. Great for developer blogs, zero hosting cost, but non-technical editors lose a dashboard.
- Move to a headless CMS. Sanity, Contentful, Payload, or Strapi give editors a modern admin while keeping the API-driven frontend. This is the common "WordPress replacement" for teams.
- Custom database. Overkill for most content sites, but an option if content is deeply app-specific.
My take: only go full-migration once the headless version is stable and you're sure you won't miss the WordPress editor. Doing both jumps at once multiplies the risk for no real reason.
Frequently asked questions
Migrating WordPress to Next.js is worth it when speed and developer experience genuinely matter — but the work that decides success isn't the React, it's revalidation, caching, and redirects. Start headless, wire up on-demand revalidation early, keep your URLs identical, and migrate one section at a time. Get those four right and the rest is just components.


