Headless WordPress · Lesson 17 of 22 · 10 min

How headless WordPress works

WordPress keeps the writing tools, Astro takes over the website. Here's how the two talk.

Lots of businesses already run on WordPress. Their team knows the editor and doesn’t want to learn Markdown and git. You can keep WordPress for writing and use Astro for the website. That setup is called headless WordPress.

The two halves

WordPress (backend) Astro (frontend)
Who uses it Editors, at /wp-admin Visitors
What it does Stores posts, pages, images Turns them into fast HTML
Hosted on Any WordPress host Vercel
Theme Not used Your Astro components

WordPress has a built-in REST API. Every site exposes its content as JSON at /wp-json/wp/v2/. Astro fetches that JSON at build time and runs it through the same components you already built.

What changes in your project

By the end of this module:

  • Blog posts come from WordPress instead of src/content/blog/
  • The About page comes from a WordPress page
  • Featured images from WordPress show on post cards
  • Publishing in WordPress rebuilds the Vercel site automatically

What stays the same: Header, Nav, Section, Card, BaseLayout, /blog, /blog/[id], and every URL. You’re only swapping where the data comes from. That’s the payoff of the content collection you set up in lesson 11.

Look at the API

Open this in your browser:

https://wordpress.org/news/wp-json/wp/v2/posts?per_page=1

That’s the official WordPress news blog, served as JSON. The fields you’ll use:

Field What it is
slug URL-friendly name, like wordpress-7-1-5-release
title.rendered Post title (may contain HTML entities like ’)
excerpt.rendered Short summary, as HTML
content.rendered Full post body, as HTML
date_gmt Publish date in UTC
featured_media ID of the featured image

Useful endpoints and options

URL Returns
/wp-json/wp/v2/posts Published posts
/wp-json/wp/v2/pages Published pages
/wp-json/wp/v2/categories Categories
/wp-json/wp/v2/media Uploaded images
?per_page=100 Up to 100 results per request (the max)
?page=2 The next 100
?_embed Includes the featured image, author, and categories in the same response
?slug=about Just the item with that slug

The tradeoffs

  • Rebuilds. A static site only changes when it rebuilds. Lesson 22 makes WordPress trigger that for you.
  • Theme features don’t carry over. Anything a WordPress theme or plugin prints on the page (contact forms, sliders, page builders) won’t appear. Astro renders the content, not the theme.
  • Two things to host. WordPress somewhere, Astro on Vercel. Visitors only ever hit Vercel.