To migrate from WordPress to Astro, export your posts and pages to Markdown (or fetch them from the WordPress REST API), load them into an Astro content collection, rebuild your theme as Astro layouts, and keep every URL identical or redirected. Done carefully, a WordPress to Astro move keeps your search rankings while removing the database, PHP and plugin updates from the public site.
This guide covers both migration paths, then walks through content, URLs, images, SEO metadata, RSS, forms and launch checks in the order you should do them.
Key Takeaways
- Decide first: a one-time export to Markdown (WordPress goes away) or headless WordPress (editors keep the dashboard).
- Crawl the old site and list every URL before you change anything. Matching URLs is what protects rankings.
- Load posts with a
glob()loader and a Zod schema insrc/content.config.ts.- Download images into the repo and serve them through
astro:assets.- Replace plugins with static equivalents: sitemap integration, RSS, a form service, a search tool.
Choose your migration path
There are two ways to move a site from WordPress to Astro, and the choice shapes everything after it.
| One-time export to Markdown | Headless WordPress | |
|---|---|---|
| Where content lives | Markdown files in your repo | WordPress database |
| Who edits | Developers, or a Git-based CMS | Editors in the WordPress dashboard |
| WordPress after launch | Switched off | Kept, but private |
| Build data source | Local files | REST API or WPGraphQL at build time |
| Ongoing upkeep | Astro dependencies only | Astro plus WordPress updates |
| Best for | Brochure sites, blogs maintained by developers | Teams that publish often and love the editor |
If you are not sure, start with the export. It is simpler, removes the most maintenance, and you can add a CMS later. The rest of this guide follows the export path and notes where headless differs. For a broader decision between the platforms, read Astro vs WordPress for business sites.
Step 1: Inventory the old site
Before touching any code, record what exists:
- Every URL. Crawl the site with a crawler, or download
sitemap_index.xmlfrom your SEO plugin. Include posts, pages, category and tag archives, author pages and paginated archives. - Top pages. Export the pages with the most clicks from Google Search Console. These must keep working on day one.
- Permalink format. Check Settings, then Permalinks. Common formats are
/post-name/,/2024/03/post-name/and/blog/post-name/. - Plugins that output front-end features. Forms, sliders, search, comments, galleries, popups and shortcodes all need replacements.
- SEO metadata. Custom titles and meta descriptions from Yoast or Rank Math, which a plain export often misses.
Keep this list in a spreadsheet. You will use it again for redirects and launch checks.
Step 2: Export content to Markdown
In the WordPress admin, go to Tools, then Export, and download the full WXR (XML) file. Then convert it to Markdown with frontmatter. The open-source wordpress-export-to-markdown tool does this well and can download images too:
npx wordpress-export-to-markdown
It prompts for the export file and output options, and writes one folder or file per post with frontmatter such as title, date, categories, tags and coverImage. Review a few posts by hand: shortcodes, embedded galleries and page-builder markup often need cleaning, because they were rendered by plugins that will not exist anymore.
Move the posts into your Astro project:
# adjust the source folder to match the tool's output
mkdir -p src/content/blog
cp -r output/posts/* src/content/blog/
If you are going headless instead, skip the export. Astro will fetch posts from https://your-site.com/wp-json/wp/v2/posts at build time, as shown in step 4.
Step 3: Create the Astro project and collection
Start a new project, or begin from a finished design so you are not rebuilding your theme from scratch:
npm create astro@latest my-site
cd my-site
npx astro add mdx sitemap
Define a collection whose schema matches the exported frontmatter. Make fields optional where some posts lack them:
// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const blog = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/blog' }),
schema: ({ image }) =>
z.object({
title: z.string(),
date: z.coerce.date(),
description: z.string().optional(),
categories: z.array(z.string()).default([]),
tags: z.array(z.string()).default([]),
coverImage: image().optional(),
}),
});
export const collections = { blog };
Run npm run dev. Any post with broken frontmatter fails with a clear message naming the file and field, which is the fastest way to find export problems. The content collections guide explains loaders and schemas in depth, and the Content Collections docs show how Komal themes structure them.
Step 4: Rebuild URLs exactly
Your new routes must produce the same paths as WordPress. For a /post-name/ permalink structure, a root-level dynamic route does it:
---
// src/pages/[slug].astro
import { getCollection, render } from 'astro:content';
import PostLayout from '../layouts/PostLayout.astro';
export async function getStaticPaths() {
const posts = await getCollection('blog');
return posts.map((post) => ({
params: { slug: post.id },
props: { post },
}));
}
const { post } = Astro.props;
const { Content } = await render(post);
---
<PostLayout title={post.data.title} description={post.data.description}>
<Content />
</PostLayout>
For date-based permalinks, use src/pages/[year]/[month]/[slug].astro and build year and month from post.data.date. Match WordPress’s trailing slash behavior with trailingSlash: 'always' in astro.config.mjs, since WordPress URLs end in a slash by default. The trailing slash tip covers the details.
For headless WordPress, getStaticPaths() fetches instead:
// inside getStaticPaths() in src/pages/[slug].astro
const res = await fetch('https://cms.example.com/wp-json/wp/v2/posts?per_page=100');
const posts = await res.json();
return posts.map((post) => ({ params: { slug: post.slug }, props: { post } }));
The REST API returns at most 100 items per request, so loop over pages using the X-WP-TotalPages response header for larger sites.
Step 5: Redirect anything that changes
Some URLs will change, such as old category archives, attachment pages or ?p=123 links. Redirect each one with a permanent redirect. Simple cases go in astro.config.mjs:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
site: 'https://www.example.com',
trailingSlash: 'always',
integrations: [mdx(), sitemap()],
redirects: {
'/category/news/': '/blog/',
'/feed/': '/rss.xml',
'/about-us/': '/about/',
},
});
On a static build, Astro writes a small HTML page with a meta refresh for each redirect. For true 301 responses, also add a public/_redirects file on Cloudflare Pages or Netlify, or redirects in vercel.json. The redirects tip shows each format.
Step 6: Move images
Images exported from wp-content/uploads/ should live in the repo, next to posts or in src/assets/, so Astro can optimize them. Reference them with relative paths in Markdown, and Astro processes them at build time. For cover images, the schema’s image() helper validates the path and gives you an object you can pass to <Image />:
---
// src/components/PostCover.astro
import { Image } from 'astro:assets';
const { cover, alt } = Astro.props;
---
{cover && <Image src={cover} alt={alt} widths={[480, 960, 1440]} sizes="(min-width: 960px) 960px, 100vw" />}
If you keep headless WordPress, allow its domain under image.domains in astro.config.mjs so remote images can be optimized too.
Step 7: Carry over SEO metadata
Plain WXR exports include titles and content but not always the custom SEO title and meta description from Yoast or Rank Math. Export those separately (both plugins store them as post meta), and add them to frontmatter as description and an optional seoTitle. Then render them in one head component with a canonical URL, Open Graph tags and JSON-LD. The Astro SEO checklist has a complete component to copy.
Also recreate:
- Sitemap:
@astrojs/sitemapwritessitemap-index.xml. Submit it in Search Console. - RSS:
@astrojs/rssbuilds a feed; redirect/feed/to it so subscribers keep receiving posts. - robots.txt: a static file in
public/or a small endpoint.
Step 8: Replace plugins
Map each front-end plugin to a static-friendly replacement:
| WordPress plugin type | Astro replacement |
|---|---|
| Contact form | A form service (Formspree, Netlify Forms, Web3Forms) or an Astro Action on an on-demand route |
| Site search | Pagefind, which indexes the built site |
| Comments | Giscus or a hosted comment service, or drop comments |
| SEO plugin | Head component, sitemap integration, JSON-LD |
| Caching or speed plugin | Not needed: pages are static and served from a CDN |
| Security plugin | Not needed for the public site: no login or database |
| Page builder layouts | Astro components and layouts |
Step 9: Launch and monitor
- Deploy to a preview URL and check every URL from your inventory returns 200 or a 301 to the right page.
- Compare titles, descriptions and canonical tags on your top pages against the old site.
- Point the domain at the new host. See the deploy guide for each platform.
- Submit the new sitemap in Search Console and watch coverage and 404 reports for a few weeks.
- Keep a backup of the WordPress database and files for a while, in case you need to recover anything.
Rebuilding a custom theme is often the slowest step. A finished design shortens it: the Blog & Editorial Astro themes already include post layouts, archive pages and author sections you can drop exported Markdown into. The official WordPress migration guide on docs.astro.build lists community tools as well.
FAQ
How long does it take to migrate WordPress to Astro?
A small blog or brochure site with a ready-made design can move in a day or two. Sites with hundreds of posts, custom post types, page-builder layouts or many plugins take longer, mostly for cleaning content and replacing plugin features. Plan extra time for URL checks before launch.
Will I lose SEO rankings when moving from WordPress to Astro?
Not if URLs stay the same or redirect with 301s, titles and descriptions carry over, and content does not change much. Rankings can shift briefly during any migration, so monitor Search Console and fix 404s quickly.
Can I keep using WordPress to write posts after moving to Astro?
Yes. Use WordPress as a headless CMS: Astro fetches posts from the REST API or WPGraphQL at build time, and a deploy hook rebuilds the site when you publish. Editors keep the dashboard, and the public site becomes static.
How do I convert WordPress posts to Markdown?
Export a WXR file from Tools, then Export, in the WordPress admin, and convert it with a tool such as wordpress-export-to-markdown. It writes Markdown files with frontmatter and can download images. Check posts that used shortcodes or page builders by hand.
What happens to WordPress forms and comments in Astro?
They need replacements, because the plugins that powered them no longer run. Use a form service or an Astro Action on an on-demand route for forms, and a hosted tool such as Giscus for comments, or remove comments entirely.