Development6 min read
Headless WordPress examples and architectural patterns
Examine headless WordPress examples across static blogs, documentation hubs, and omnichannel apps. Learn real setups, code patterns, and trade-offs.
By Hamza Ahmad AslamFull-Stack & WordPress Engineer
On this page
- Core architectures behind headless WordPress examples
- Example 1: Editorial publishing with static regeneration
- The publishing flow
- Example 2: Enterprise technical documentation and knowledge base
- Search indexing integration
- Example 3: Omnichannel content distribution
- How to setup headless WordPress: core steps
- Step 1: Redirect frontend requests
- Step 2: Configure Cross-Origin Resource Sharing (CORS)
- Step 3: Configure frontend data retrieval
- Backend performance and caching trade-offs
- Common pitfalls in headless WordPress projects
- Frequently asked questions
Short answer: Practical headless WordPress examples divide the platform into two separate systems: WordPress acting solely as a structured content repository, and an external frontend framework rendering the user interface. Typical production architectures include static publishing pipelines built with modern site generators, dynamic corporate portals using Next.js, and mobile applications consuming the native REST API or WPGraphQL. Decoupling the presentation layer isolates administrative operations and eliminates theme constraints, though it requires managing two hosting stacks and custom cache invalidation pipelines.
Core architectures behind headless WordPress examples
Decoupling WordPress means disabling or ignoring the traditional PHP template hierarchy (such as single.php or archive.php). The WordPress application handles user authentication, custom post types, editorial revisions, and database storage, while an independent client queries the data over HTTP as JSON.
Real deployments typically fall into three patterns:
- Static site generation with incremental updates: WordPress runs on an internal server or private subdomain. An external static generator builds HTML files at deploy time and re-renders individual pages when editors publish changes.
- Dynamic server-side rendering: A Node.js or edge runtime generates HTML for every request, pulling fresh content from the WordPress API with server-side caching layers.
- Native and omnichannel applications: WordPress is the central editorial backend, exposing endpoints to iOS and Android applications, digital signage, and single-page web applications simultaneously.
Each setup alters the operational burden. When deciding whether decoupling matches your organisation, reviewing the architectural assessment in headless WordPress with Next.js: when it fits helps clarify the development costs.
Example 1: Editorial publishing with static regeneration
A classic pattern involves high-traffic blogs and news rooms where content changes frequently throughout the editorial day, but visitors require instant page loads. In this model, editors write in the block editor on admin.example.com, while visitors access static HTML cached across a global content delivery network on example.com.
The publishing flow
The hosting environment runs WordPress behind basic authentication or an IP allowlist. When an editor clicks publish, WordPress fires an action hook that sends an HTTP POST request to a webhook endpoint on a platform such as Vercel or Cloudflare Pages.
Here is how you register a lightweight webhook trigger in your child theme or custom plugin using save_post in WordPress 6.x:
<?php
declare(strict_types=1);
add_action('save_post', 'prefix_trigger_build_webhook', 10, 3);
function prefix_trigger_build_webhook(int $post_id, WP_Post $post, bool $update): void {
// Ignore auto-drafts, revisions, and non-public updates
if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {
return;
}
if ($post->post_status !== 'publish') {
return;
}
$webhook_url = defined('FRONTEND_BUILD_HOOK') ? FRONTEND_BUILD_HOOK : '';
$api_secret = defined('BUILD_SECRET_TOKEN') ? BUILD_SECRET_TOKEN : '';
if (empty($webhook_url)) {
return;
}
wp_remote_post($webhook_url, [
'timeout' => 5,
'blocking' => false,
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $api_secret,
],
'body' => wp_json_encode([
'post_id' => $post_id,
'slug' => $post->post_name,
'type' => $post->post_type,
]),
]);
}
This architecture keeps traffic spikes entirely away from MySQL and PHP. Your database never executes queries when viral traffic arrives, because visitors only download pre-built HTML, CSS, and compressed images.
Example 2: Enterprise technical documentation and knowledge base
Companies often select WordPress because non-technical teams already know how to format content, manage taxonomies, and schedule releases. However, product documentation often requires advanced client-side search, custom code syntax engines, and integration with Git-based versioning.
In a headless documentation setup, teams configure WordPress custom post types for articles, guides, and API references. The frontend application fetches content via the WordPress REST API (opens in a new tab) and pipes the markdown or HTML through modern layout engines.
Search indexing integration
Instead of relying on MySQL LIKE queries or heavy search plugins inside the WordPress dashboard, a headless architecture offloads document indexing to external search engines like Meilisearch, Typesense, or Algolia. A WordPress hook pushes clean post content to the search index upon publishing. The frontend executes client-side search requests straight to the search engine, returning results in milliseconds without touching the origin server.
Separating the presentation also strengthens your perimeter. Securing your database and admin endpoints becomes simpler when public traffic never touches your PHP environment directly, as covered in our WordPress security hardening checklist.
Example 3: Omnichannel content distribution
When content must reach desktop browsers, mobile apps, and point-of-sale displays at the same time, maintaining separate CMS engines creates duplicate work. In this pattern, WordPress operates as a headless data warehouse.
| Frontend Target | Delivery Format | Query Strategy |
|---|---|---|
| Web Application | Server-Rendered HTML | WPGraphQL with edge cache |
| iOS / Android App | Native JSON Views | REST API with JWT authentication |
| In-Store Display | Static Asset Bundles | Polling REST API via cron |
Using WPGraphQL allows client developers to request exact data shapes. For example, a mobile device checking for a daily notification might request only the post title, permalink, and an excerpt, avoiding the transmission of large HTML blobs over cellular networks.
query GetLatestAnnouncements {
posts(first: 5, where: { categoryName: "Announcements" }) {
nodes {
databaseId
title
date
excerpt
}
}
}
This structure decouples release cycles. Frontend teams can redesign native components and publish app updates without modifying underlying WordPress databases, custom post types, or editorial workflows.
How to setup headless WordPress: core steps
Setting up a headless instance requires preparing WordPress to work cleanly as an API origin rather than a website engine.
Step 1: Redirect frontend requests
Prevent visitors and search bots from indexing default themes or accessing empty template pages on your backend domain. Add this snippet to a custom plugin or your active functions file:
<?php
declare(strict_types=1);
add_action('template_redirect', 'prefix_disable_public_frontend');
function prefix_disable_public_frontend(): void {
// Allow API endpoints, cron jobs, and admin requests to continue
if (is_admin() || wp_is_json_request() || (defined('DOING_CRON') && DOING_CRON)) {
return;
}
// Redirect visitors hitting root URLs to the admin dashboard or external site
wp_safe_redirect(admin_url(), 301);
exit;
}
Step 2: Configure Cross-Origin Resource Sharing (CORS)
If your decoupled frontend runs on example.com and your WordPress installation resides on cms.example.com, browsers block JavaScript fetch requests by default. You must configure explicit headers in your web server. On Nginx, specify your permitted origin within the server configuration block:
location /wp-json/ {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' 'https://example.com' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type' always;
add_header 'Access-Control-Max-Age' 86400;
return 204;
}
add_header 'Access-Control-Allow-Origin' 'https://example.com' always;
try_files $uri $uri/ /index.php?$args;
}
Step 3: Configure frontend data retrieval
In your modern application layer, create a reliable fetch helper. If you are building with Next.js, use native fetch with revalidation tags, as described in the Next.js data fetching documentation (opens in a new tab):
interface PostSummary {
id: number;
slug: string;
title: { rendered: string };
content: { rendered: string };
}
export async function getPostBySlug(slug: string): Promise<PostSummary | null> {
const res = await fetch(`https://cms.example.com/wp-json/wp/v2/posts?slug=${encodeURIComponent(slug)}`, {
next: { tags: [`post-${slug}`], revalidate: 3600 },
});
if (!res.ok) {
return null;
}
const posts: PostSummary[] = await res.json();
return posts.length > 0 ? posts[0] : null;
}
Backend performance and caching trade-offs
Moving to headless changes where latency occurs. Traditional WordPress sites rely on page caching plugins that save fully generated HTML on disk. When you switch to an API-first approach, your frontend application continuously requests JSON data from the backend.
Without preparation, this increases database load because complex REST API or GraphQL queries must repeatedly resolve post metadata, taxonomy terms, and user permissions.
To keep API responses fast:
- Install a persistent cache: Store query results in memory instead of reading from MySQL on every request. Follow the configuration steps in our guide on WordPress Redis object cache setup.
- Cache JSON responses at the edge: Set reverse-proxy rules using Cloudflare or Fastly to cache
/wp-json/responses, using custom header invalidation when posts update. - Monitor origin response latency: If your Node.js server takes hundreds of milliseconds simply awaiting JSON responses from WordPress, read our guide on how to reduce WordPress TTFB to isolate backend bottlenecks.
Decoupled setups do not solve slow backend code automatically. If your database queries are poorly indexed or your wp_options table is bloated, your API responses will drag down build times and dynamic rendering routines.
Common pitfalls in headless WordPress projects
Before separating your stack, account for the capabilities that traditional themes manage automatically.
- Draft previews break easily: WordPress expects to display drafts on its internal URL. Building a preview system requires creating a signed token route in your frontend application that retrieves unpublished content safely.
- SEO and metadata management: Plugins like Yoast or Rank Math populate
<meta>tags automatically in standard themes. In a headless environment, you must install companion plugins that expose SEO meta fields over the REST API or WPGraphQL, then manually map those fields to your frontend layout components. - Visual editor parity: Content authors expect the block editor to match their site styles. A decoupled frontend means you must either recreate your design system styles inside the WordPress admin editor, or editors will work in an unstyled visual environment.
If your organization needs bespoke user experiences, native mobile delivery, or strict isolation between marketing editors and internal servers, these headless WordPress examples offer tested blueprints for production.
If you need help architecting, securing, or optimizing a headless WordPress implementation, get in touch to discuss your project.
Frequently asked questions
Is WordPress headless by default?
No, WordPress is traditionally a monolithic CMS that ships with its own PHP-based templating engine. However, because it includes the built-in REST API and supports WPGraphQL, it functions as a headless CMS whenever you fetch content through endpoints instead of loading standard themes.
Is WordPress a good choice as a headless CMS?
WordPress is an effective choice when editorial teams already know its admin interface and require mature plugin support for workflows. It is less suitable if your team wants a lightweight, schema-only content layer without the operational weight of a full PHP and MySQL stack.
How do you handle post previews on a headless WordPress site?
You handle previews by generating a temporary cryptographic token in WordPress and redirecting the editor to an authenticated route on your frontend application. The frontend server validates the token, queries the draft post using an administrative API key, and displays the unpublished content.
What is the difference between using the REST API and WPGraphQL for headless setups?
The core REST API comes built into WordPress without extra configuration and works well for simple endpoints. WPGraphQL requires an open-source plugin but lets frontend applications request exact fields in a single query, reducing network payload sizes and eliminating multiple HTTP round-trips.
Enjoyed this? Get the next article by email.
Keep reading
Development
4 min read
AI automation for small businesses: where to start
A practical guide to AI automation for small businesses: choose one workflow, set review rules, estimate costs and test failures before launch.
- Automation
- Web Development
- Small Business
Development
5 min read
Headless WordPress with Next.js: when it fits
Decide whether headless WordPress with Next.js fits your site. Review plugin compatibility, previews, caching, hosting and the work involved.
- WordPress
- Next.js
- Headless CMS
Enterprise
2 min read
WordPress VIP development: code review, caching and releases
WordPress VIP development guidance on code analysis, bounded queries, cache invalidation and release checks, with a practical local PHPCS command.
- WordPress VIP
- Enterprise
- Code Quality