Headless WordPress projects promise flexibility, performance, and scalability—but the journey is rarely smooth. When GlobeVM, an enterprise cloud and cybersecurity provider, made the leap from a traditional monolith to a headless architecture, we encountered challenges that tested our backend and frontend stacks alike. By transforming a single monolithic WordPress site into a decoupled system using Next.js, React, and a headless CMS, we unlocked faster load times, improved security, and a more agile content workflow. But the path was paved with debugging sessions, architectural pivots, and creative problem-solving.
The result? A 100% headless WordPress site that powers GlobeVM’s global presence—faster, more secure, and easier to maintain. Here’s how we overcame six major hurdles along the way, along with the code and strategies that made it possible.
A Lean Stack Built for Speed and Security
Our architecture was designed to balance performance, developer experience, and content management efficiency. The frontend runs on Next.js with the App Router, deployed on Vercel for edge caching and global CDN support. The backend remains WordPress, hosted on Cloudways, but stripped of its traditional theme layer and repurposed solely as a headless CMS.
We leveraged Advanced Custom Fields Pro (ACF) and Custom Post Type UI to structure complex content types—like service pages, case studies, and blog posts—without bloating the frontend. For SEO, we relied on Yoast SEO Premium, accessed via the REST API to ensure metadata accuracy across thousands of pages. Caching was split strategically: Vercel handled static ISR (Incremental Static Regeneration) at the edge, while Redis Object Cache on Cloudways kept backend queries fast and database load low.
{
"frontend": "Next.js (App Router), React, Vercel",
"backend": "WordPress on Cloudways",
"cms": "ACF Pro + CPT UI",
"seo": "Yoast SEO Premium",
"caching": "Vercel Edge Cache (ISR) + Redis Object Cache"
}While the stack looked simple on paper, the real work began when we started integrating these tools under one roof.
Solving the API Spaghetti: The BFF Pattern
In the early days, our Next.js frontend was making eight separate fetch() calls just to render the blog homepage. We needed data for posts, authors, categories, tags, ACF fields—and each call used messy query strings like ?_fields=id,title,acf&_embed. The result? Slow page loads, redundant database queries, and a frontend that felt more like a data aggregator than a content site.
We adopted the Backend-For-Frontend (BFF) pattern by building a custom WordPress plugin. Instead of forcing Next.js to juggle multiple endpoints, we created a single master API route: /wp-json/gvm/v1/blog-home. This endpoint aggregated all required data—posts, featured articles, categories, and ACF metadata—into one clean JSON response. We cached the result using WordPress transients and Redis, reducing database hits to near zero.
add_action('rest_api_init', function () {
register_rest_route('gvm/v1', '/blog-home', [
'methods' => 'GET',
'callback' => 'gvm_blog_home_endpoint',
'permission_callback' => '__return_true'
]);
});With this change, Next.js now makes just one API call. The homepage loads instantly, and our content team gains a single source of truth for all frontend data.
Taming Custom SVG Icons and ACF Field Quirks
Our design relied heavily on custom SVG icons for service cards and interactive elements. WordPress, however, blocks SVG uploads by default due to security concerns, and ACF image fields refused to play nicely with Next.js image optimization.
We resolved this in two ways:
- Plugin route: We installed Safe SVG, a lightweight plugin that sanitizes SVG files during upload, allowing WordPress to accept and serve them safely.
- Code route: For full control, we used a PHP snippet to manually sanitize SVGs before storing them in the media library. AI-assisted refactoring helped validate the sanitization logic.
Once uploaded, we exposed the SVGs via our REST API and rendered them in Next.js using inline <svg> elements or optimized components.
Building a Controlled Comment System with Zero Replies
GlobeVM’s content policies required a strict one-layer comment system: no nested replies, and all comments must be approved by an admin. This violated WordPress’s default behavior, where threads can grow arbitrarily deep and users can post without moderation.
We rebuilt the comment system from the ground up:
- GET endpoint: Created a custom
/wp-json/abc/v1/commentsroute that fetched only approved comments and structured them as a flat Parent/Child JSON tree. - POST endpoint: Built a secure endpoint to accept new comments, but with a critical guardrail: an “Absolute Root Finder” in PHP. This loop checked every incoming comment’s parent ID. If it pointed to a reply (non-zero parent), the server forcibly reparented it to the root post (parent ID = 0).
- Admin UI override: Used the
comment_row_actionsfilter to hide the “Reply” button in the WordPress dashboard for any comment that already had a child. This prevented accidental rule-breaking by editors.
The result: a comment system that enforces policy without sacrificing usability.
Tracking Article Views in a Static World
WordPress thrives on real-time data, but Next.js with ISR generates static HTML at build time. That meant WordPress had no idea when users actually read an article—so our “Popular Articles” section was stuck showing outdated metrics.
We solved this with a silent client-side tracker. Every time a user opens a blog post in Next.js, a useEffect hook fires a lightweight POST request to a custom WordPress endpoint: /wp-json/abc/v1/track-view/{post_id}. WordPress increments a view_count meta field for that post. Our /popular-posts API then queries posts ordered by this meta value.
useEffect(() => {
fetch(`/wp-json/abc/v1/track-view/${postId}`, { method: 'POST' });
}, [postId]);This approach adds minimal overhead while giving us accurate, real-time view analytics—even in a static frontend.
Enabling WordPress Draft Previews on Vercel
One of the biggest hurdles in headless setups is previewing unpublished drafts. How do you let an editor click “Preview” in WordPress when the frontend lives on Vercel?
We hijacked the WordPress preview logic using the preview_post_link filter. When an admin clicks “Preview,” WordPress redirects them to a Vercel API route:
`
Next.js verifies the token, activates Draft Mode, and loads the correct React template based on the route parameter. To fetch unpublished content securely, we used Application Password authentication via HTTP Basic Auth. We also added autosave detection in PHP (wp_get_post_autosave), so editors see live updates without saving the draft.
This seamless preview flow maintains the familiar WordPress experience while leveraging Vercel’s performance and scalability.
Breaking the Double Cache Trap
Production releases revealed a classic headless trap: Next.js cached the frontend, WordPress cached the backend, and updates didn’t propagate. An admin could edit a post, save it, and the live site wouldn’t reflect the change for hours—or ever.
We eliminated all traditional WordPress caching plugins (WP Rocket, Breeze, Varnish) as they interfered with the headless API. Instead, we relied solely on:
- Redis Object Cache on Cloudways to speed up backend queries.
- On-Demand Revalidation using the WP Webhooks plugin. Every time an admin clicks “Update Post,” WordPress fires a webhook to Vercel, which instantly purges the ISR cache for that specific URL.
This ensures visitors always see the latest content without sacrificing speed or performance.
Lessons for Your Headless WordPress Project
GlobeVM’s transition to headless WordPress wasn’t just a technical upgrade—it was a cultural shift. We learned that success hinges on three pillars:
- Design your API layer first. Avoid spaghetti fetches by consolidating endpoints and leveraging BFF architectures.
- Enforce policy at the API level. Don’t rely on frontend validation or UI overrides alone.
- Cache smartly, cache selectively. Traditional caching plugins often break headless setups. Use Redis for backend speed and Vercel’s ISR for frontend performance.
As headless WordPress matures, more teams will face these challenges. The good news? With the right architecture and a bit of ingenuity, each hurdle becomes a stepping stone—not a roadblock. Whether you’re building a corporate site, a SaaS blog, or a dynamic knowledge base, the headless approach delivers unmatched flexibility. Just plan for the pitfalls.
Ready to go headless? Start small, iterate fast, and let your API do the heavy lifting.
AI summary
Discover how GlobeVM overcame six headless WordPress challenges using Next.js, Redis, and custom endpoints. Learn the tech stack and solutions for your own project.