Editorial wants the WordPress experience they know — Gutenberg, drafts, scheduling, ACF blocks. Engineering wants the production footprint of a static site — no PHP at the edge, no WP attack surface, no plugin compatibility matrix during a release. Astro in front of WP-as-headless is the pragmatic answer. The boring failure mode is what happens after launch: a content team that publishes 80 posts a week notices that some changes land in five seconds and others take six hours, the on-call sees rebuild storms during European morning, and someone in marketing keeps emailing screenshots of pages that “should be live by now.”
What’s happening
Astro is a static-first framework. By default, astro build queries WordPress at build time, renders Markdown/MDX from getStaticPaths, and ships HTML. The rendered shell is fast, but the freshness model is “whatever was true at the last build.” Three behaviors break in production:
Build-time fetching with no on-publish hook. If your only refresh is a cron-driven astro build, every editorial change has a worst-case staleness equal to the cron interval. Hourly rebuilds are fine for blogs; they are not fine for a press desk that publishes corrections.
Astro v4’s hybrid mode is per-page, not per-content-type. output: 'hybrid' lets you mark specific routes as server-rendered, but if you mix SSR pages and SSG pages in the same project, you have two cache layers (Astro’s fetch cache and your CDN’s edge cache) and two invalidation paths. People conflate them.
Draft preview needs an authenticated path. Astro built pages are public HTML. Previews of unpublished WP posts have to bypass the static cache and authenticate against WP — usually by hitting a server-rendered route that calls WP with a JWT or app password. That route has to exist and has to be excluded from your CDN’s edge caching, or the first authenticated preview is cached and served to everyone.
The healthy pattern: SSG with explicit on-publish rebuilds, an SSR route for previews, and a webhook from WP that fires astro build or, if you’re on Vercel/Netlify/Cloudflare Pages, triggers an incremental rebuild of the affected paths only.
How to verify
Find out where Astro is fetching from and how often. Open astro.config.mjs and check the output mode:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
site: 'https://www.example.com',
output: 'static', // or 'hybrid', or 'server'
integrations: [sitemap()],
});
If output is static, every page in src/pages/ is built at deploy time. Confirm where the WP fetch happens:
grep -r "getStaticPaths" src/pages/ | head
grep -rn "wp-json\|graphql" src/ | head
A typical SSG fetch in an Astro page:
// src/pages/[slug].astro
---
export async function getStaticPaths() {
const res = await fetch('https://cms.example.com/wp-json/wp/v2/posts?per_page=100&_embed');
const posts = await res.json();
return posts.map((post) => ({
params: { slug: post.slug },
props: { post },
}));
}
const { post } = Astro.props;
---
<article>
<h1 set:html={post.title.rendered} />
<div set:html={post.content.rendered} />
</article>
To check whether on-publish rebuilds are wired, look on the WP side for a webhook plugin or a save_post action:
# In wp-content/mu-plugins/ or wp-content/plugins/
grep -rn "save_post\|publish_post\|wp_remote_post" wp-content/mu-plugins/
To check what the CDN is actually serving for a recent post, hit it with curl and read the cache headers:
curl -sI https://www.example.com/articles/recent-correction/ \
| grep -iE 'cache-control|age|x-cache|cf-cache-status'
If age: is in the thousands and the last build was an hour ago, the CDN is holding a stale render. If x-cache: HIT shows for a URL that was supposed to be invalidated on publish, the deploy webhook never fired or your CDN purge step never ran.
The fix
The production pattern has four moving parts: an SSG project for public pages, an SSR route for authenticated previews, a WP-side webhook on post publish, and a CDN purge step after deploy.
First, configure Astro for hybrid output so previews can be server-rendered while everything else stays static:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';
export default defineConfig({
site: 'https://www.example.com',
output: 'hybrid',
adapter: node({ mode: 'standalone' }),
vite: {
server: {
fs: { allow: ['..'] },
},
},
});
Then mark the preview route as SSR and exclude it from edge caching:
// src/pages/preview/[id].astro
export const prerender = false;
---
import { getDraftPost } from '../../lib/wp';
const id = Astro.params.id;
const token = Astro.url.searchParams.get('token');
if (!token) {
return new Response('Missing token', { status: 401 });
}
const post = await getDraftPost(id, token);
if (!post) {
return new Response('Not found', { status: 404 });
}
Astro.response.headers.set('Cache-Control', 'private, no-store');
---
<article>
<h1 set:html={post.title.rendered} />
<div set:html={post.content.rendered} />
</article>
The fetch helper authenticates with an application password against the WP REST API:
// src/lib/wp.js
const WP_BASE = import.meta.env.WP_BASE; // https://cms.example.com
const WP_USER = import.meta.env.WP_PREVIEW_USER;
const WP_PASS = import.meta.env.WP_PREVIEW_PASS; // WP application password
export async function getDraftPost(id, token) {
const expected = import.meta.env.WP_PREVIEW_TOKEN;
if (token !== expected) return null;
const auth = Buffer.from(`${WP_USER}:${WP_PASS}`).toString('base64');
const res = await fetch(`${WP_BASE}/wp-json/wp/v2/posts/${id}?status=draft,private,publish&_embed`, {
headers: { Authorization: `Basic ${auth}` },
});
if (!res.ok) return null;
return res.json();
}
Drop a mu-plugin on the WordPress side that fires a webhook on every relevant transition. A mu-plugin is loaded before regular plugins and is harder for an editor to deactivate by accident:
<?php
// wp-content/mu-plugins/sh-headless-webhook.php
add_action('transition_post_status', function ($new_status, $old_status, $post) {
if ($post->post_type !== 'post' && $post->post_type !== 'page') return;
if ($new_status === 'auto-draft' || $new_status === 'inherit') return;
$payload = [
'post_id' => $post->ID,
'slug' => $post->post_name,
'status' => $new_status,
'previous' => $old_status,
'type' => $post->post_type,
'timestamp' => time(),
];
wp_remote_post('https://deploy.example.com/hooks/astro-rebuild', [
'timeout' => 5,
'blocking' => false,
'headers' => [
'Content-Type' => 'application/json',
'X-Webhook-Secret' => SH_WEBHOOK_SECRET,
],
'body' => wp_json_encode($payload),
]);
}, 10, 3);
The receiver — a small Node service or a serverless function — debounces (so a burst of saves doesn’t trigger ten builds) and either calls the deploy provider’s build hook or, if you control the build, runs astro build and pushes the result to your CDN. After the deploy completes, purge the affected URLs:
# Cloudflare example — purge specific URLs on deploy completion
curl -X POST "https://api.cloudflare.com/client/v4/zones/$CF_ZONE/purge_cache" \
-H "Authorization: Bearer $CF_API_TOKEN" \
-H "Content-Type: application/json" \
--data '{"files":["https://www.example.com/articles/recent-correction/","https://www.example.com/articles/","https://www.example.com/"]}'
Two things to keep in the runbook. Rebuild storms during European morning happen when an editorial team schedules ten posts at 09:00 and your build takes four minutes — debounce the webhook with at least a 30-second window. And slug drift: WordPress lets editors rename a slug on a published post; if you don’t purge the old URL, the old static page sits in your CDN serving 404s from the edge for hours. The mu-plugin should include the old slug from transition_post_status’s $post_before so the receiver can purge both URLs.
Stack Harbor operates headless WP stacks where the editorial team is on WordPress and the public site is rendered by Astro, Next.js, or Nuxt — see enterprise WordPress hosting for the operating model, and Deployment Management for the webhook and CDN purge plumbing. If your team is choosing between a managed headless setup and rolling your own, we can scope it.