Headless WordPress
Headless WordPress forms with Core Forms — the calm way to embed a WP form on Astro, Next.js, Vue, or plain HTML
Use WordPress as a form backend and render the form anywhere — Astro, Next.js, plain HTML, or a mobile webview. Three integration modes, one API key.
You’ve moved the rest of your site off WordPress. The marketing pages live in Astro, the docs sit on Next.js, the storefront runs on something else entirely. But you still need a form — and real form infrastructure (storage, spam filtering, admin moderation, email notifications, webhooks to your CRM) is not something you want to rebuild from scratch.
Core Forms 4.1.0 added a first-class headless mode for exactly this. WordPress stays where it is, doing what it’s good at — storing submissions, running the spam filters, firing the action loop. The form HTML, the submit POST, and the rendered response all happen on a completely different origin.
This post walks through what “headless forms” actually means in practice, the three integration modes Core Forms ships, the security model, and a handful of footguns worth knowing about.
What “headless” means here
A normal WordPress form lives entirely inside the WordPress page. The HTML is rendered by PHP, the submit POST goes to admin-ajax.php, the response shows inline. WP-Admin reads the submissions, Email Logs traces the notifications, the whole flow is one cookie domain.
A headless form moves the render and the submit off-WordPress. The HTML is fetched from the WP REST API (or copied once and pasted in), the submit POST goes from your Astro/Next/Vue origin to wp-json/core-forms/v1/forms/{id}/submit, and the response comes back as JSON.
What stays on the WordPress side:
- Form storage (the form definition, fields, settings)
- Submission storage (when the form saves entries, with status: new / read / spam)
- Spam protection (reCAPTCHA v3, Cloudflare Turnstile, Akismet, honeypot)
- The action loop (email, webhooks, Slack, WhatsApp, Mailchimp, FluentCRM, et cetera)
- Admin UI for everything above
What moves off-WordPress:
- Where the form is displayed
- Where the user types
- Where the success message renders
That’s it. From the WP-Admin perspective, a saved submission from your Astro site lands in the same submissions table as one from a WP-rendered page and runs the actions you’ve enabled. Behind a proxy, the recorded IP is your server’s.
Three integration modes
Core Forms ships three flavours of the same headless API. Pick whichever fits.
1. The drop-in embed.js widget (vanilla JS, zero build step)
Once the setup below is done, paste two lines into any HTML page:
<div data-cf-form="contact" data-cf-key="ABC123…"></div>
<script src="https://your-wp-site.com/wp-json/core-forms/v1/embed.js" defer></script>
The script fetches the form HTML from your WP REST endpoint, injects it into the target div, intercepts submission, and POSTs the data back as JSON. WordPress validates the entry and the script shows the success or error message. The form takes your site’s CSS, because the embed doesn’t load WordPress styles or scripts. That also means steps, conditional fields, live calculations and file uploads don’t work in it.
This is the path of least resistance. No build step, no framework, no JS knowledge required. Works on plain HTML, in a CMS where you can paste a script tag, inside a Webflow embed, inside a WordPress page on a different WordPress site, anywhere.
2. Native fetch (Astro, Next.js, Vue, React, Svelte, whatever)
For sites with a JS framework, skip the embed script and call the REST API directly:
// Fetch the form schema (HTML + fields)
const res = await fetch('https://your-wp-site.com/wp-json/core-forms/v1/forms/contact');
const form = await res.json();
// Submit user input
await fetch('https://your-wp-site.com/wp-json/core-forms/v1/forms/contact/submit', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Core-Forms-Key': 'ABC123…'
},
body: JSON.stringify({
name: 'Ada',
email: 'ada@example.com',
_cf_page_url: window.location.href
})
});
The schema response includes the rendered HTML, a structured field list (for client-side validation), the form’s messages, the submit URL, and a requires_captcha flag. The flag is true whenever a Turnstile or reCAPTCHA site key is saved, even if Turnstile is off for that form.
3. Server-side proxy (the production-grade option)
The first two modes ship the API key to the browser, where anyone can copy and abuse it. The same key works for every headless form on your site. If you accept that for newsletter signups or low-stakes contact forms, we recommend keeping a captcha on, watching for spam and rotating the key when you see abuse.
For anything beyond that, proxy through your own backend. Our headless docs have copy-paste starters for:
- Cloudflare Workers / Pages Functions
- Next.js App Router route handlers
- Astro server endpoints
The frontend posts to your own /api/submit route without an API key. Your backend sets id to the form’s ID (replacing any value from the browser), accepts only plain values and lists, adds the X-Core-Forms-Key header and forwards to WordPress. The key never lands in the browser bundle.
The security model
The headless endpoints exist only while Core Forms → Modules → Headless API is on, and it’s off by default. The submit endpoint is gated by a single site-wide API key, configured under Core Forms → Settings → Headless / REST. The key has to be in the X-Core-Forms-Key header on every submit (4.2.0 dropped the ?cf_key= query-string fallback, which was leaking the key into server logs and Referer headers).
Beyond the API key:
- Per-form opt-in. Every form has a Headless mode switch. The headless API rejects forms with it off, even with a valid key.
- Allowed origins. List your frontends under Core Forms → Settings → Headless / REST → Allowed origins, one per line. The list isn’t access control, so treat the form schema and submit responses as readable by any website, script or server. An empty list reflects the request’s origin.
- Captcha needs setup on your site. Core Forms checks reCAPTCHA v3 and Turnstile tokens on headless submissions, but the external site has to load the captcha script and be listed as a hostname with the provider. Akismet runs when its module is on. Behind a proxy, all three see your server’s IP, so send a real submission before launch.
- A proxy hides the visitor’s IP. An
X-Forwarded-Forheader doesn’t change what Core Forms records. For proxied forms, we recommend setting the form’s rate limit to 0, rate limiting the proxy itself and turning off duplicate prevention. - Honeypot still applies. Core Forms adds an empty one to API requests, so your frontend can leave it out. If you send it, keep it empty, because a filled one gets a success response and nothing is saved.
- No visitor nonce. The endpoint doesn’t need a WordPress nonce, and Allowed origins can’t stand in for one. We recommend a proxy that checks the origin and keeps the key private, plus a captcha.
Variables that need a little care
Submitter context variables — [CF_REFERRER_URL], [CF_POST_ID], [CF_USER_AGENT] — work out of the box when the form is rendered server-side by PHP, because PHP can read the Referer header and $_SERVER directly.
In a headless submission, the Referer header doesn’t give WordPress the full page URL. Browsers strip the cross-origin Referer to just the origin under the default strict-origin-when-cross-origin policy. Behind a proxy, [CF_IP_ADDRESS] is your server’s IP, and [CF_USER_AGENT] is the visitor’s only if your route forwards it, as our starters do.
Core Forms 4.2.0 fixed the referrer variables by reading the page URL from a _cf_page_url field in the JSON body. The bundled embed.js forwards window.location.href automatically; if you’re using the native-fetch path, add it explicitly:
body: JSON.stringify({
name: 'Ada',
email: 'ada@example.com',
_cf_page_url: window.location.href // ← do this
})
Without that field, don’t rely on [CF_REFERRER_URL] to show the page the visitor filled the form on.
What you don’t lose
The fear with any headless setup is that you’re trading away admin power for clean architecture. With Core Forms you’re not.
- Submissions still appear in WP-Admin when the form saves them. Open Core Forms → Submissions, filter by inbox / spam / all, mark as read, reply to the submitter, export to CSV.
- The full action loop still fires. Send Email, Auto-Responder, Mailchimp, FluentCRM, HubSpot, ConvertKit, Slack, Discord, Telegram, Twilio SMS, the three WhatsApp actions, Notion, Airtable, Google Sheets, Webhooks, Zapier, Make, Create User, Create Post: an accepted submission runs the actions you’ve enabled.
- Payments and uploads stay on WordPress. Payment forms need a page hosted on WordPress. So do file uploads, because JSON doesn’t carry files. Link to that page from your site. Our fields and features guide shows which route suits each feature.
- Email Logs catch every notification. Failed sends show up in Core Forms → Email Logs the same way they always have. Resend works for email-class action types.
A typical setup walkthrough
From start to finish:
- Turn on the module. In WP-Admin, go to Core Forms → Modules and turn on Headless API. It’s off by default.
- Generate an API key. Go to Core Forms → Settings → Headless / REST, click Generate. Save the settings.
- Add allowed origins. Same page — add the production origin and any staging origins, one per line.
- Flip the per-form toggle. Open a form, head to the Headless tab, turn on Headless mode and click Save Form.
- Set up a captcha. Turn on Turnstile or reCAPTCHA v3 before the form goes public, and load its script on the external site.
- Copy a snippet. The Headless tab shows three pre-filled snippets: the drop-in widget, native fetch, and cURL. They contain your real API key, so use placeholders when you share code or screenshots.
- Paste it into your Astro / Next / plain-HTML site, or use a proxy starter to keep the key private. Then send a test submission.
If draft publishing is on, publish the form, because headless requests use the published version. Accepted submissions land in WP-Admin when the form saves entries.
When not to use this
The headless mode is great for a particular pattern: WordPress as backend, modern frontend stack as the visitor-facing site. It’s not the right fit for every form.
Skip it if:
- Your whole site is already WordPress. Use the Gutenberg block or shortcode. You get the form theme, the browser-side features and the same admin UI, with zero extra moving parts.
- You need a WordPress session. Headless submissions don’t have one. A form that requires login or depends on session-bound checks belongs on a page hosted on WordPress.
- Your frontend can’t reach your WordPress backend. If WordPress sits behind a VPN or on a private network, browsers outside it can’t use the embed. A proxy works only if its server can reach WordPress.
For forms without payments or uploads, like marketing sites on Astro, docs sites on Next.js, signup forms on plain HTML or “request a demo” forms on a separate landing page, headless mode is the calm answer to “where does the form actually live?”
WordPress, where it always has. Just rendered somewhere else.
See it in action: Core Forms → Integrations → Headless / REST
The server side is the same whichever front end you use: the after-submit workflow covers actions and retries, and the webhooks piece covers getting the data out again.