Skip to content
CMS and web technologies

Astro and WordPress: How a Headless WordPress Site Really Works

Keep the WordPress admin your team knows and give visitors a fast Astro site. How the data flows, what breaks, what to rebuild and what it costs to run two systems.

Harsh PrajapatiFull stack developer
Published
Reading time
10 min

Astro and WordPress: How a Headless WordPress Site Really Works

Using Astro with WordPress means WordPress stays as the place your team writes and edits content, while Astro builds the public website by reading that content through the WordPress REST API (or WPGraphQL). Visitors get fast, mostly static pages, and editors keep the admin they already know. The catch is that anything your WordPress theme and plugins did on the front end, such as SEO tags, previews, forms, comments and menus, now has to be wired into Astro by hand.

This guide is for business owners, marketing leads and agencies weighing a headless WordPress site with Astro, and for developers who want the gaps listed in one place. If you would rather hand the whole build to a team, our Astro website development service covers headless WordPress from start to finish.

How Astro and WordPress fit together

WordPress becomes a content store and Astro becomes the website. Editors write and publish in WordPress as before, and Astro fetches each post as JSON and turns it into HTML with its own templates, not your theme.

The official Astro guide to headless WordPress (opens in a new tab) uses the REST API that ships with every WordPress site. Posts live at /wp-json/wp/v2/posts, pages at /wp-json/wp/v2/pages, and reading published content needs no authentication. Custom post types must be exposed to the REST API before Astro can see them.

Astro can build every page ahead of time as plain HTML (a static build), or fetch content when a visitor asks for a page (on-demand rendering, which needs a server or edge platform). A blog or service site can run as a static build with a rebuild on publish, plus on-demand rendering for any pages that need fresh data.

REST API or WPGraphQL

The REST API is the simpler choice and is enough for a typical blog, brochure or service site. It is built in, and Astro's guide shows two helpful query options: _fields to return only the fields you need, and _embed to include related items such as featured images in the same response. Lists return a limited number of items by default and at most 100 per request, as the WordPress pagination docs (opens in a new tab) explain, so a site with more posts needs to page through the results using the X-WP-TotalPages header.

WPGraphQL is a free plugin that adds a /graphql endpoint. You write one query that asks for a post, its ACF fields, its author and its SEO data together. Version 2.0, released in February 2025, dropped support for PHP below 7.4 and WordPress below 6.0, according to the WPGraphQL v2 announcement (opens in a new tab). It pays off on large, nested content models; on a small brochure site it is one more plugin to update.

REST APIWPGraphQL
InstallBuilt into WordPressFree plugin
Request styleOne URL per resource typeOne query for exactly the fields you want
ACF fieldsShow in REST API toggle per field groupNeeds the WPGraphQL for ACF plugin
Yoast datayoast_head_json added to responsesNeeds an add-on plugin
Best forBlogs, brochure and service sitesLarge, nested content models

A simple fetch in Astro

This is a static Astro page that builds one page per WordPress post. It asks only for the fields it uses.

ASTRO
---
// src/pages/blog/[slug].astro
export async function getStaticPaths() {
  const res = await fetch(
    "https://cms.example.com/wp-json/wp/v2/posts?per_page=100&_fields=slug,title,content,yoast_head_json"
  );
  const posts = await res.json();
  return posts.map((post) => ({ params: { slug: post.slug }, props: { post } }));
}
const { post } = Astro.props;
---
<h1 set:html={post.title.rendered} />
<article set:html={post.content.rendered} />

WordPress sends titles and content as HTML, so Astro's set:html directive outputs them without escaping. Only do that with content from editors you trust.

ACF fields and menus

ACF fields are hidden from the REST API until you switch them on. In each field group, open Group Settings and turn on Show in REST API; the values then appear under an acf key in the post's JSON. The ACF REST API documentation (opens in a new tab) says this arrived in ACF 5.11, and that an acf_format=standard parameter returns full image details instead of bare IDs.

Menus are easy to forget. WordPress has REST endpoints for menus, but they are not public by default: reading them needs a logged-in user with the right permissions. Since WordPress 6.8, a rest_menu_read_access filter lets a developer expose chosen menus publicly, as the WordPress 6.8 developer note (opens in a new tab) explains. The other honest option is to define the main menu in Astro's code, which is fine when it changes twice a year.

SEO data from Yoast or Rank Math

You can keep Yoast or Rank Math and feed their output into Astro. With Yoast active, the standard REST responses for posts, pages and other content carry yoast_head (ready-made tags) and yoast_head_json (the same data as fields: title, description, canonical, robots, Open Graph, Twitter and the schema graph). The Yoast REST API docs (opens in a new tab) note the JSON form needs Yoast SEO 16.7 or later, and Yoast also offers a /wp-json/yoast/v1/get_head?url= route for any URL. Rank Math has a Headless CMS Support (opens in a new tab) option under General Settings, Others, which lets a front end call /wp-json/rankmath/v1/getHead?url= with a full page URL.

The trap is the domain. If WordPress lives at cms.example.com, the canonical URL, og:url and every URL inside the schema graph will point there, not at www.example.com. Astro must rewrite those URLs to the public domain before printing them, and the WordPress front end itself should redirect to the Astro site or be marked noindex. Sitemaps and redirects move too: Astro should generate the sitemap of public URLs, and plugin-managed redirects move to the Astro config or your host.

Draft preview for editors

The WordPress Preview button opens the old theme, not Astro, so preview needs three parts:

  1. A WordPress filter, preview_post_link, changes the Preview button to point at an Astro preview route, passing the post ID and a secret.
  2. The Astro preview route is rendered on demand, checks the secret, and fetches the draft by ID with an authenticated request.
  3. Authentication uses an Application Password, which WordPress has shipped since 5.6, sent over HTTPS from the server only.

Drafts are fetched by ID because an unpublished post may not have its final slug yet. Never put the Application Password in browser code.

PHP
add_filter( 'preview_post_link', function ( $link, $post ) {
    return 'https://www.example.com/preview?id=' . $post->ID . '&secret=' . PREVIEW_SECRET;
}, 10, 2 );

Forms and comments on a headless site

Forms and comments stop working when the theme goes, so plan them before the build. A form plugin's shortcode inside post content relies on the WordPress front end to submit, so it will not send from Astro.

Practical options for forms:

  • Astro Actions. Type-safe server functions that accept form data. The Actions guide (opens in a new tab) says a page that posts a form to an action must be rendered on demand.
  • A form service or your CRM's own form, which suits static sites with no server.
  • The form plugin's own API, if it has one, called from an Astro server route so no keys reach the browser.

Comments work through /wp-json/wp/v2/comments, but anonymous visitors cannot post there unless a developer enables the rest_allow_anonymous_comments filter, which is off by default. Spam protection then becomes your job, so it is worth asking whether the site needs comments at all.

Images

WordPress keeps storing your media. To let Astro resize and convert images that live on the WordPress domain, add that domain to image.domains or image.remotePatterns in the Astro config, as the Astro images guide (opens in a new tab) shows. Images from domains not on the list still display, but Astro does not optimise them.

Images inside post content arrive as HTML in content.rendered, so Astro's image component does not touch them, and they still load from the CMS host. That host must stay quick and reachable.

Rebuilds, webhooks and live content

New posts reach a static Astro site through a rebuild. Hosts such as Netlify and Cloudflare Pages offer a deploy hook: a secret URL that starts a build when it receives a POST request. WordPress has no webhook screen of its own, so a small snippet (or a plugin) calls that URL when a post is published or updated:

PHP
add_action( 'transition_post_status', function ( $new, $old, $post ) {
    if ( 'publish' === $new || 'publish' === $old ) {
        wp_remote_post( DEPLOY_HOOK_URL );
    }
}, 10, 3 );

The alternative is live content. Astro 6 (opens in a new tab), released on 10 March 2026, made live content collections stable: content is fetched when a page is requested, so updates appear without a rebuild. The content collections guide (opens in a new tab) says live collections need an adapter for on-demand rendering and do not support image optimisation. Astro 7 (opens in a new tab), released on 22 June 2026, made route caching stable, so pages rendered on demand can be cached, and live content can carry cache tags that clear just the affected pages.

ApproachNew content appearsHostingGood for
Static build plus deploy hookAfter the next build finishesStatic hostingBlogs, service and brochure pages
Live content collectionsOn the next requestServer or edge runtimePrices, stock, news that must be current
Mix of bothPer pageServer or edge runtimeSites with a few fast-changing pages

If you would rather not wire up previews, SEO data and rebuild hooks yourself, our Astro team can set up the whole headless WordPress pipeline for you.

Hosting WordPress on a subdomain

A tidy layout is WordPress on a subdomain such as cms.example.com, and Astro on the main domain. That keeps the public site free of PHP and plugins, and lets you lock down the CMS: limit who can reach /wp-admin, and keep WordPress's own sitemaps and front end out of search results. If you also run WooCommerce, the cart and checkout can stay on WordPress; our post on a headless WooCommerce store with Astro covers that setup.

The real cost of running two systems

Headless WordPress with Astro is two products to look after, not one. WordPress still needs updates, backups and security monitoring even though visitors never see it, and the Astro site needs its own hosting, updates and a developer for new layouts.

ItemTraditional WordPressHeadless WordPress with Astro
Systems to hostOneTwo (WordPress and the Astro site)
Page builder layoutsEdited by your teamRebuilt as Astro components, since builder CSS and scripts do not carry over
SEO plugin outputPrinted by the themeRead from the API and rendered by Astro
Forms and commentsPlugins work as installedRebuilt or replaced
Front end security surfaceWordPress and every pluginStatic files, CMS hidden on a subdomain
Page speedDepends on theme and pluginsFast by default

Headless is worth it when speed, security or a custom design matter more than letting editors build new layouts themselves. When the budget is tight and your team builds pages often, a well-made WordPress theme is still the better buy; our comparison of Astro and WordPress for a business website walks through that choice.

Where to start

Start with an inventory, not code: list your post types, ACF field groups, menus, forms, SEO plugin, redirects and page builder pages. That list decides whether the REST API is enough, whether you need on-demand rendering, and how long the build takes.

If WordPress is not a must for your editors, compare the options in our guide to the best headless CMS for Astro and our earlier headless CMS comparison. Leaving WordPress completely? See WordPress to Astro migration. When you are ready, our Astro website development and WordPress development teams can scope both sides with you and give you a written quote before any work starts.

Frequently asked questions

Do I need a plugin to use WordPress with Astro?

No. The WordPress REST API is built in and serves published posts and pages without any plugin or login. Plugins or small snippets are only needed for extras such as GraphQL, previews and rebuild hooks.

Will my Yoast or Rank Math SEO settings still work?

Yes, if the Astro site reads them. Yoast adds yoast_head_json to REST responses and Rank Math offers a getHead endpoint once Headless CMS Support is on. Astro must print those tags and rewrite canonical and schema URLs from the CMS domain to your public domain.

Can editors still preview drafts?

Yes, with some setup. The Preview button is pointed at a private Astro route that fetches the draft by ID using an Application Password on the server.

How quickly do new posts appear on the Astro site?

On a static site, once the rebuild that a deploy hook starts when you publish has finished. Build time depends on the size of the site and the host. With Astro live content collections and on-demand rendering, new content appears on the next page request.

Sources

The facts in this article were checked against these pages, last reviewed 26 November 2026.

  1. Headless WordPress and Astro, Astro Docsdocs.astro.build/en/guides/cms/wordpress/
  2. REST API pagination, WordPress Developer Resourcesdeveloper.wordpress.org/rest-api/using-the-rest-api/pagination/
  3. WPGraphQL v2.0 is here, WPGraphQLwpgraphql.com/2025/02/13/wpgraphql-v2-0-is-here-what-you-need-to-know/
  4. ACF WP REST API integration, Advanced Custom Fieldsadvancedcustomfields.com/resources/wp-rest-api-integration/
  5. New REST API filter for exposing menus publicly in WordPress 6.8, Make WordPress Coremake.wordpress.org/core/2025/03/27/new-rest-api-filter-for-exposing-menus-publicly-in-wordpress-6-8/
  6. Yoast SEO REST API, Yoast developer portaldeveloper.yoast.com/customization/apis/rest-api/
  7. Rank Math Headless CMS Support, Rank Math knowledge baserankmath.com/kb/headless-cms-support/
  8. Actions, Astro Docsdocs.astro.build/en/guides/actions/
  9. Images, Astro Docsdocs.astro.build/en/guides/images/
  10. Astro 6, Astro blogastro.build/blog/astro-6/
  11. Astro 7, Astro blogastro.build/blog/astro-7/
  12. Content collections, Astro Docsdocs.astro.build/en/guides/content-collections/
Harsh Prajapati, the author

Written by

Harsh Prajapati

Freelance full stack developer, founder of Worklancio

Web developer since 2018, freelancing since 2022. Builds WordPress sites and plugins, web apps and CRMs from Ahmedabad.

You may also like