You have two main ways to integrate React with WordPress:
Headless (Decoupled) WordPress → React as a separate frontend using the REST API or GraphQL.
Embedded React App inside a WordPress Theme or Plugin → React components run within WordPress pages.
Below, you’ll learn both approaches.
⚙️ Option 1: Headless WordPress with React Frontend
In this setup, WordPress acts as a content API, and React is your frontend app.
✅ Step 1: Setup WordPress Backend
Install WordPress locally or on a server.
Enable REST API (enabled by default in modern WP).
You can test it by visiting:Install useful plugins:
JWT Authentication for WP REST API (for secure login/auth).
WPGraphQL (optional, for GraphQL support)
✅ Step 2: Create a React App
Run:
✅ Step 3: Fetch WordPress Data
In your React app, open src/App.js and replace with:
Then run:
✅ You’ll now see your WordPress posts displayed in your React frontend!
✅ Step 4: Deploy Separately
Host your WordPress site (for backend & content).
Host your React app (Netlify, Vercel, etc.).
React will keep fetching data from your WordPress domain.
🧱 Option 2: Integrate React Inside WordPress Theme/Plugin
✅ Step 1: Build Your React App
Create and build your React app:
This creates a /build folder with static assets.
✅ Step 2: Add React Build to WordPress Theme
Copy the /build contents into your WordPress theme folder:
✅ Step 3: Enqueue React Scripts in functions.php
In your theme’s functions.php:
function enqueue_react_app() {
wp_enqueue_script(
'my-react-app',
get_stylesheet_directory_uri() . '/react-app/static/js/main.js',
array(),
null,
true
);
wp_enqueue_style(
'my-react-app-style',
get_stylesheet_directory_uri() . '/react-app/static/css/main.css',
array(),
null
);
}
add_action('wp_enqueue_scripts', 'enqueue_react_app');✅ Step 4: Add React Root Div in Template
In your theme’s template (like page-react.php):
✅ Step 5: Create a Page and Assign Template
In WordPress Admin → Pages → Add New.
Select “React Page” template.
Publish → Visit Page → React App loads inside WordPress!
Bonus Tips
Use Axios for advanced API requests.
For authenticated routes, use the JWT plugin and
Authorizationheader.For SEO, consider Next.js + WP REST API instead of plain React.
🚀 Best Stack Recommendation (2025)
If you want a fast, SEO-friendly modern setup, go with:
WordPress (Headless Backend)
Next.js (React Framework)
WPGraphQL + Apollo Client
This gives you static generation, dynamic routes, and headless CMS flexibility.