React and WordPress are two of the most popular tools in web development. React is known for building fast, interactive user interfaces, while WordPress is the world’s most widely used content management system. Many developers today combine these two technologies by using WordPress as a Headless CMS and React as the front-end.
This powerful combination offers the best of both worlds:
In this guide, you will learn what a headless CMS is, why React + WordPress is a great choice, and how to integrate both step-by-step.
A Headless CMS means that WordPress only manages content, but does not handle the front-end.
Instead, WordPress acts like a content API. The content is fetched by a front-end application (React, Next.js, Vue, Angular, etc.) through REST API or GraphQL.
Editors can still use the WordPress admin panel they already know.
React builds fast, interactive interfaces that load instantly without page reloads.
No PHP templates on the front-end reduces security risks.
You can use WordPress only for content and deploy your React app anywhere (Vercel, Netlify, AWS).
You can display WordPress content on:
WordPress (Headless) → REST API / GraphQL → React Front-End
React fetches all content using:
https://yourwordpresssite.com/wp-json/wp/v2/posts
This API returns JSON data which React can show on the website.
Good news — the WordPress REST API is already enabled by default. You can test it by opening:
https://yourwebsite.com/wp-json/
If you see JSON output, your REST API is working.
React (running on localhost:3000) must be allowed to access WordPress.
Add this to your .htaccess:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
Header set Access-Control-Allow-Headers "Content-Type, Authorization"
</IfModule>
Optional (restrict only to your domain):
Header set Access-Control-Allow-Origin "https://yourreactapp.com"
Run this command:
npx create-react-app my-app
cd my-app
npm start
Your React app will run at:
http://localhost:3000/
Create a React component:
import React, { useEffect, useState } from "react";
function BlogPosts() {
const [posts, setPosts] = useState([]);
useEffect(() => {
fetch("https://yourwebsite.com/wp-json/wp/v2/posts")
.then(res => res.json())
.then(data => setPosts(data));
}, []);
return (
<div>
<h1>Latest Posts</h1>
{posts.map(post => (
<div key={post.id}>
<h2 dangerouslySetInnerHTML={{ __html: post.title.rendered }} />
<div dangerouslySetInnerHTML={{ __html: post.excerpt.rendered }} />
</div>
))}
</div>
);
}
export default BlogPosts;
This component displays all WordPress posts inside your React frontend.
Developers looking for Copilot-style AI help without paying a subscription.
Use dynamic routing:
import { useParams } from "react-router-dom";
function SinglePost() {
const { id } = useParams();
const [post, setPost] = useState(null);
useEffect(() => {
fetch(`https://yourwebsite.com/wp-json/wp/v2/posts/${id}`)
.then(res => res.json())
.then(data => setPost(data));
}, [id]);
if (!post) return <p>Loading...</p>;
return (
<div>
<h1 dangerouslySetInnerHTML={{ __html: post.title.rendered }} />
<div dangerouslySetInnerHTML={{ __html: post.content.rendered }} />
</div>
);
}
Now each post displays full content.
Install:
npm install react-router-dom
Setup routes:
import { BrowserRouter, Routes, Route } from "react-router-dom";
import BlogPosts from "./BlogPosts";
import SinglePost from "./SinglePost";
function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<BlogPosts />} />
<Route path="/post/:id" element={<SinglePost />} />
</Routes>
</BrowserRouter>
);
}
export default App;
You can deploy the front-end using:
The WordPress backend can stay on your normal hosting.
Install the plugin:
GraphQL is faster than REST and gives more control. Example query:
{
posts {
nodes {
id
title
content
}
}
}
In React, you can use Apollo Client to fetch GraphQL data.
Use headless WordPress if you need:
Using React with WordPress as a headless CMS is one of the most powerful setups for modern web development. You get WordPress’s easy content management and React’s performance, flexibility, and interactivity.
Whether you’re building a blog, portfolio, business website, or full web app — this combination gives you speed, control, and scalability.