Headless WordPress, locally: copying the CMS and the frontend
The 30-second version
A headless WordPress site is two apps: WordPress stores the content, and a separate front end (often Next.js) shows it. Copy WordPress into Local like a normal site, then switch off any plugin that sends data elsewhere, like search indexing. Get the front end’s code, install the Node version it asks for, and point it at your local WordPress in .env.local, checking every setting, not just the WordPress address. Then change something locally and make sure the front end shows it.
On this page
When I started working on my first headless WordPress site, I didn’t really know what “headless” meant. I knew it had something to do with WordPress being the back end, so the front end could be “put” anywhere: a website, an app, whatever. What I didn’t know was what that would mean the first time I had to copy the site onto my computer.
It turns out a headless site is two apps, and copying it means copying both. It also means a local copy that looks completely local can still be talking to the live services behind the scenes. I found that out the hard way, with a staging site full of links pointing at my computer.
This post builds on running a live WordPress site on your computer. The WordPress half gets copied exactly the same way, so start there if you haven’t already. This time the made-up example-bakery.com has gone headless: WordPress still holds the menu, the opening hours and the blog, but visitors see a separate Next.js app. By the end you’ll have both running on your computer: WordPress at example-bakery.local, and the front end at localhost:3000, reading from it.
A kitchen and a shop front, in two different buildings
In a normal WordPress site, the kitchen (where content is made) and the shop front (what visitors see) are the same building. WordPress does both.
In a headless site, they’re split up. WordPress is only the kitchen: you still write and edit content in the WordPress admin. The shop front is a separate app that asks the kitchen for content and shows it however it likes. Because the kitchen doesn’t care who’s asking, the same content can feed a website, a phone app, or both. “Headless” just means WordPress has had its head (the part visitors see) taken off.
How the shop front asks the kitchen for things
The front end can’t walk into WordPress and look around. It sends questions to one address, usually /graphql, like “give me the title and photo of every cake”. GraphQL is the language those questions are written in, and WPGraphQL is the WordPress plugin that understands them and answers.
That one address is the most important setting in this whole post. Whatever it points at is where your front end gets its content from.
Visitors never talk to WordPress directly
- WordPressStores the content
- GraphQLAnswers the front end’s questions
- Next.js appBuilds the pages
- VisitorSees the site
Why a headless copy is trickier
A normal WordPress copy is mostly self-contained: you copy it, and everything you click happens on your computer.
A headless site is different. Both halves are full of settings that point at other places: the WordPress address, a search service, maps, analytics, a button that rebuilds the live site. Copy everything without changing those settings, and you get two apps running on your laptop that still talk to live services. It looks local. It isn’t.
So the real work in this post isn’t installing things. It’s going through every setting, on both halves, and deciding: should this point at my local copy, a test service, or nothing at all?
Step 1:Copy the WordPress side
Follow the WordPress copy post: back up production, pull the site into Local (I use Local Connect), and make the copy safe in wp-config.php.
Two things look different on a headless site:
- Opening the site in a browser shows a blank page, or sends you to the live site. That’s normal: a headless theme usually has nothing to show visitors. If Open site sends you to example-bakery.com, close that tab. The WordPress half is working if WP Admin loads.
- Local Connect only copies WordPress. The front end isn’t part of the pull. It lives in its own Git repo, which comes later.
Local also has a headless add-on that can run the front end for you. I don’t use it: I pull WordPress with Local Connect and run the front end from its own folder, which is what this post covers.
Step 2:Switch off anything in WordPress that talks to other services
This is the step I wish I’d known about. Plugins keep their settings in the database, and the database came across in the pull. So any plugin that sends data somewhere is still set up to send it to the real place.
On a headless site, look especially for:
- Search plugins that send your content to a separate search service.
- “Rebuild site” or “Deploy” buttons that tell the front end’s host to rebuild. Pressed from your local copy, they can rebuild staging or production.
- Anything with an API key in its settings: maps, email marketing, CRMs.
For each one, empty the connection settings in your local WordPress admin, or point them at a test account. Do it before you edit or save anything.
My staging search filled up with links to my computer
The site used a hosted search service, and a WordPress plugin kept it up to date: every time a page was saved, the plugin sent that page to the search service. The plugin’s connection settings came across with the database, still pointing at the shared staging search.
So every time I saved something locally, the plugin quietly sent it to staging, with my local address in its links. Nothing looked wrong on my computer. It was the staging site’s search results that were suddenly full of links to example-bakery.local.
Blocking outside requests in wp-config.php (from the WordPress copy post) didn’t catch it, because the plugin talked to the search service directly instead of going through WordPress’s own request system. Some plugins do that, so don’t rely on that setting alone.
Step 3:Check WordPress is answering GraphQL questions
Before touching the front end, make sure the kitchen is open. In your local WordPress admin, open the GraphQL menu and choose GraphiQL IDE (called GraphQL IDE in newer versions). Run this tiny query:
{
generalSettings {
title
url
}
}If you get your site’s title back, WordPress is ready to answer the front end. The url should be https://example-bakery.local (or http://). If it’s the live address, the search-replace from the WordPress copy post missed something.
Step 4:Get the front-end code and the right Node version
Clone the front end’s repo into its own folder, outside your Local site. I keep mine next to it, like Local Sites/example-bakery-frontend.
Then check which version of Node it needs. Look for an .nvmrc file, an engines field in package.json, or a note in the README. Older projects often won’t install or build on the newest Node, and newer ones won’t run on an old one.
# nvm-windows doesn't read .nvmrc, so type the version out
nvm install 24
nvm use 24
# On Mac or Linux (nvm), or with fnm, this reads .nvmrc for you
nvm use
# Install exactly what's in package-lock.json
npm ciIf the terminal still feels unfamiliar, this post covers the basics.
Why one computer needs several Nodes
Node.js is what runs the front end’s JavaScript on your computer. Projects are built against a particular version, and a project from a few years ago may break on today’s. A version manager (nvm, nvm-windows, fnm or Volta) lets you keep several versions installed and switch per project, like keeping different chargers for different phones.
The settings that live outside the code
Some settings shouldn’t be baked into the code: passwords, API keys, and which server to talk to. They live in small text files called .env files, one NAME=value per line. The app reads them when it starts. Change the file, restart the app, and the same code talks to a different server.
Step 5:Point the front end at your local WordPress
Next.js reads several .env files, and .env.local beats the usual shared ones. That makes it the right place for your settings. It’s normally in .gitignore too, so nothing you put there gets committed (check, though).
- Read the files the project gives you first, like
.env.exampleor.env.development. List every setting the app uses, not just the WordPress one. - Create
.env.localin the front end’s main folder. - Point the WordPress settings at your local copy.
- Decide what to do with every other setting. If in doubt, leave it empty, or use a test value.
# Where WordPress lives. Your LOCAL copy, never the live site.
NEXT_PUBLIC_GRAPHQL_ENDPOINT=https://example-bakery.local/graphql
NEXT_PUBLIC_BACKEND_URL=https://example-bakery.local
# Where the front end itself runs (used for sitemaps and links)
SITE_DOMAIN=localhost:3000
SITEMAP_ROOT_URL=http://localhost:3000
# Staging is often password protected. Your local copy isn't.
HTTP_AUTH_REQUIRED=false
WORDPRESS_USERNAME=
WORDPRESS_PASSWORD=
# Search: empty, so nothing local reaches the real search index
SEARCH_HOST=
SEARCH_KEY=
# Analytics: empty, so you don't show up in the client's reports
NEXT_PUBLIC_GTM_ID=The names are examples. Every project names its settings differently, so use the names from the project’s own files.
When the same setting is in more than one place, Next.js uses the first one it finds, in this order (for npm run dev):
- Settings already set in your terminal or on the server
.env.development.local.env.local.env.development.env
One block per place, and only one switched on
My .env.local has a labelled block of settings for each place I might point the front end at: staging, production, and my local copy. All but one block is commented out with #. Switching is quick, but it also means one missed # and you’re pointing at staging without noticing. Whichever block is on, do the “change something” test below every time you switch.
The defaults are often the live settings
Some projects commit a .env or .env.development file to Git, and it often points straight at the live WordPress and live services. If you skip .env.local, or only override the WordPress address, everything else in those files still applies. Read every line.
Step 6:Start the front end and prove it’s reading your copy
npm run dev
# Look for the line that says Local: http://localhost:3000Open http://localhost:3000, then do the “change something” test:
- In your local WordPress admin, change something you’ll notice. Add “LOCAL” to the home page title, and save.
- Reload the front end.
- If the title changed, the front end is reading your local copy. If it didn’t, it’s reading from somewhere else, probably staging or production. Go back to
.env.local.
This takes 30 seconds, and it’s the only way to be sure. A front end reading production looks exactly the same as one reading your copy, until you change something.
What could go wrong
The front end doesn’t trust your local HTTPS
If your Local site uses HTTPS, Node may refuse to connect, with an error like self-signed certificate or unable to verify the first certificate. Local made that certificate itself, and Node doesn’t trust it.
The simplest fix is http:// for the local WordPress address in .env.local. You’ll also see NODE_TLS_REJECT_UNAUTHORIZED=0 suggested, which switches the check off. If you use it, put it only in `.env.local`, never in a file that gets committed or deployed: it turns off a real security check for the whole app.
Images from your local WordPress don’t load
Next.js’s <Image> component only shows images from addresses on an approved list in next.config.js (images.remotePatterns). The live WordPress is on it. Your local one isn’t.
Since Next.js 16 there’s a second catch: it refuses to optimise images from addresses on your own computer or network, which includes example-bakery.local. So even after adding it to the list, images can fail with a “400” error. There is a setting to allow it, but it’s called dangerouslyAllowLocalIP for a reason. The safer fix is to skip image optimisation during development only:
module.exports = {
images: {
// Serve images as-is while developing locally
unoptimized: process.env.NODE_ENV === 'development',
remotePatterns: [
{protocol: 'https', hostname: 'example-bakery.com'},
],
},
}Restart npm run dev after changing next.config.js.
Not every address comes from .env
Some addresses are written straight into the code: in next.config.js, in small scripts, or in the WordPress theme itself. Search both halves for the live domain once, at the start:
# Find every mention of the live site
git grep -n "example-bakery.com"Watch out for code that picks an address based on where it’s running, like “if this is the staging site, use staging’s address; otherwise…”. Look at what happens in the “otherwise”. Your local copy matches none of the real sites, so it gets whatever the fallback is, and sometimes the fallback is staging.
Some things are switched off on purpose in development
Projects often skip things when you run npm run dev. For example, redirects that the front end normally loads from WordPress might be turned off locally. If something works on staging but not on your computer, search the code for development before you start debugging. It might be off on purpose.
Forms might not send email the way you expect
Find out where each form actually goes. If the front end hands form entries to a form plugin in WordPress (through GraphQL), then WordPress sends the emails, and the email protections from the WordPress copy post apply.
Some front ends send email themselves, with their own email settings in .env. Those never go near WordPress. Empty those settings in .env.local, so a test submission can’t reach a real inbox.
Scripts in package.json aren’t always harmless
Before you run anything other than npm run dev, read the scripts section of package.json. Some scripts send data somewhere: building a sitemap with whatever address is in .env, updating a search index, or deploying. A script with “deploy” in its name might build the site and start it as if it were production.
Two apps, two sets of versions
In the WordPress copy post you matched WordPress and PHP versions to production. Now there’s a second app, so match the Node version too, and use npm ci to get the exact package versions in package-lock.json. A bug that only appears with one version of Next.js won’t show up if you’ve installed another.
Preview might open the wrong front end
When you click Preview in the WordPress admin, WordPress has to know where the front end lives. That address is set inside WordPress (in a plugin setting or the theme’s code), and your copy brought staging’s or production’s with it. Find where it’s set, and check what a preview from your local copy opens before you trust it.
What I’d tell past me
Do the “change something” test first, before anything else, and again every time you switch settings. It’s the only real proof of which WordPress your front end is reading from.