The WordPress REST API lets you use WordPress as a content source without its usual website design. This means you can build your website or app separately and get content from WordPress easily.
Why WordPress REST API enables headless usage
GET /wp-json/wp/v2/posts
// Example: Fetch posts from WordPress REST API endpointThe REST API uses URLs to get data in JSON format.
You can use HTTP methods like GET, POST, PUT, DELETE to interact with WordPress data.
GET https://example.com/wp-json/wp/v2/posts
GET https://example.com/wp-json/wp/v2/pages/42POST https://example.com/wp-json/wp/v2/posts
{
"title": "New Post",
"content": "This is the post content."
}This JavaScript code fetches posts from the WordPress REST API and prints each post's title and content in the console.
fetch('https://example.com/wp-json/wp/v2/posts') .then(response => response.json()) .then(posts => { posts.forEach(post => { console.log(`Title: ${post.title.rendered}`); console.log(`Content: ${post.content.rendered}`); console.log('---'); }); }) .catch(error => console.error('Error fetching posts:', error));
The REST API returns data in JSON, which is easy to use in many programming languages.
Using the REST API separates content management from how the content is shown, giving more design freedom.
Authentication is needed for creating or editing content via the API.
The WordPress REST API lets you get and manage content without using WordPress themes.
This enables building websites or apps with any technology while still using WordPress as the content backend.
It makes WordPress flexible and modern for many types of projects.
Practice
Solution
Step 1: Understand headless usage concept
Headless means separating content management from how content is shown.Step 2: Identify REST API role
The REST API lets apps get content data without using WordPress themes for display.Final Answer:
It allows access to WordPress content without relying on themes. -> Option CQuick Check:
Headless = Access content without themes [OK]
- Thinking themes are required to use REST API
- Believing REST API blocks external access
- Confusing plugins with REST API purpose
Solution
Step 1: Identify REST API method for fetching data
Fetching data uses GET requests, not POST.Step 2: Check correct REST API endpoint format
The standard posts endpoint is /wp-json/wp/v2/posts.Final Answer:
GET /wp-json/wp/v2/posts -> Option DQuick Check:
GET + /wp-json/wp/v2/posts = Correct fetch [OK]
- Using POST instead of GET to fetch posts
- Using admin URLs instead of REST API endpoints
- Mixing endpoint paths incorrectly
/wp-json/wp/v2/posts and renders the titles of posts?Solution
Step 1: Understand REST API data response
The endpoint returns JSON data with posts including titles.Step 2: React app renders fetched titles
React uses this data to show a list of post titles on screen.Final Answer:
A list of post titles from WordPress content. -> Option BQuick Check:
REST API data + React render = Post titles list [OK]
- Expecting WordPress theme output instead of JSON
- Assuming REST API returns empty without setup
- Confusing admin dashboard with API data
/wp-json/wp/v2/post but gets a 404 error. What is the likely cause?Solution
Step 1: Check endpoint spelling
The correct posts endpoint uses plural 'posts', not 'post'.Step 2: Understand 404 error meaning
404 means the URL does not exist, likely due to wrong path.Final Answer:
The endpoint path is incorrect; it should be /wp-json/wp/v2/posts. -> Option AQuick Check:
404 error + wrong endpoint = fix URL [OK]
- Using singular 'post' instead of 'posts'
- Assuming REST API is disabled without checking URL
- Blaming themes for API endpoint errors
Solution
Step 1: Understand REST API data format
The API sends content as JSON, a simple data format apps can use.Step 2: Recognize app design independence
The mobile app can use this data to show posts in its own style, no themes needed.Step 3: Confirm no plugin or theme dependency
REST API is built-in and does not require extra plugins or themes for data access.Final Answer:
It provides JSON data of posts that the app can display with its own design. -> Option AQuick Check:
REST API JSON + app design freedom = Headless usage [OK]
- Thinking WordPress themes must be used in apps
- Believing plugins are needed to export posts
- Assuming content is locked inside WordPress admin
Ready to prove it?
Pass the test and this pattern moves unknown
