The WordPress API is like a toolkit that developers use to build features inside WordPress, such as plugins or themes. It works within WordPress itself.
The WordPress REST API, however, is a way for external applications (like mobile apps or other websites) to interact with WordPress. It allows you to access WordPress data from outside, like getting posts or updating information, using simple web requests.
In short, the WordPress API is for internal development, while the WordPress REST API is for connecting WordPress to other apps or services from the outside.
Table of Contents
As of WordPress 2026 and the latest stable versions, the WordPress REST API remains an integral part of core. It has not been removed or deprecated and continues to power not only external integrations but also internal features such as the block editor and many modern plugin interfaces.
What is WordPress API?
WordPress API means the programming interfaces that WordPress provides to customize or extend its functionality. This primarily includes:
Imagine WordPress is a ready-made car that you’ve received. The car is already good and you can drive it, but you want to make some changes – like installing a custom stereo system, changing the seat colors, or adding a special feature to the dashboard.
WordPress API lets you do exactly this, but with your website. It’s basically a set of tools and instructions that WordPress gives you so you can customize your website without breaking WordPress’s core files.
![WordPress API vs WordPress REST API: With Examples [2026] 2 WordPress API visualization infographic with hooks, plugins, and customization elements like code, email notifications, and design tools.](https://apibuddy.net/wp-content/uploads/2024/09/WordPress-API-visualization-infographic-with-hooks-plugins-and-customization-elements-like-code-email-notifications-and-design-tools.webp)
For example, let’s say you have a blog website. You want to automatically write “Thanks for reading!” at the end of every post. Normally you would type this manually in each post, but using WordPress API you can write a simple code that will do this job automatically. Or if you want to receive an email whenever a new user registers – WordPress API makes this possible too.
WordPress API gives you hooks (actions and filters) which are basically “connection points“. Just like when you plug into an electrical socket you get electricity, similarly you can “plug in” your code into these hooks and change WordPress’s behavior. You don’t have to touch WordPress’s original files, just write your code and hook it in, and the work is done.
The biggest advantage of WordPress API is that you can customize WordPress in your own way while keeping it safe and updatable.
Primary WordPress API Include:
Plugin API – Hooks system:
- Actions: To run custom code at specific events (like
wp_head,save_post) - Filters: To modify data before display (like
the_content,the_title)
Theme API – Functions for theme development:
- Template tags (like
the_title(),the_content()) - To add theme support features
Database API – To safely interact with the WordPress database by running queries using the $wpdb class
Settings API – To create plugin/theme settings pages
Shortcode API – To create custom shortcodes
Basically, all these make WordPress programmable – you can write code to change or enhance WordPress’s default functionality without editing core files.
What is WordPress REST API?
WordPress REST API is a way through which you can access your WordPress website’s content from outside. Normally when you use WordPress, you log in through a browser and work in the dashboard – you write posts, edit them, etc.
![WordPress API vs WordPress REST API: With Examples [2026] 3 WordPress REST API diagram with JSON responses connecting mobile apps, React, websites, and tablets.](https://apibuddy.net/wp-content/uploads/2024/09/WordPress-REST-API-diagram-with-JSON-responses-connecting-mobile-apps-React-websites-and-tablets.webp)
What does REST API do? It’s like a “door” that allows other programs/apps to also talk to your WordPress site, without opening a browser.
WordPress REST API Real-life examples:
- Mobile app: Let’s say you’ve created a news website in WordPress. Now you want a mobile app too. Through REST API, that app can directly pull articles from your website.
- Social media automation: When you publish a post on WordPress, it automatically posts on Facebook/Twitter as well.
- Smart display: A digital screen that automatically shows your latest blog posts without anyone having to manually update it.
In simple language: Your WordPress site is a restaurant, and REST API is a delivery service that can deliver your food (content) anywhere – mobile app, another website, anywhere!
WordPress API vs WordPress REST API: Key Differences
| Aspect | WordPress API | WordPress REST API |
|---|---|---|
| Purpose | Extend/customize WordPress internally | Access WordPress data externally |
| Location | Works inside WordPress only | Works from anywhere (external access) |
| Technology | PHP functions and hooks | HTTP requests with JSON responses |
| Access Method | Direct function calls in code | URL endpoints via web requests |
| Data Format | PHP arrays/objects | JSON (JavaScript Object Notation) |
| Use Case | Building plugins and themes | Building mobile apps, headless CMS, integrations |
| Communication | Internal (server-side only) | External (over the internet) |
| Authentication | WordPress login system | API keys, OAuth, JWT tokens |
| Example | add_action('init', 'my_function') | GET https://site.com/wp-json/wp/v2/posts |
| Who Uses It | WordPress developers (PHP) | App developers (any language) |
| Availability | Always available in WordPress | Available since WordPress 4.7+ |
| Speed | Faster (direct server access) | Slower (network requests involved) |
| Independence | Tied to WordPress environment | Platform-independent |
- WordPress API = Internal toolbox for WordPress developers
- WordPress REST API = External gateway for anyone to access WordPress data
Examples of WordPress API
Here are a few code examples showcasing how to use various WordPress APIs within the WordPress environment.
1. Add Custom Text After Post Content (Filter Hook)
function add_custom_text($content) {
$custom = "<p>Thanks for reading!</p>";
return $content . $custom;
}
add_filter('the_content', 'add_custom_text');
This filter adds “Thanks for reading!” at the end of every post’s content. The the_content filter modifies the content before the post is displayed.
2. Send Email When Post is Published (Action Hook)
function notify_on_publish($post_id) {
$post = get_post($post_id);
wp_mail('[email protected]', 'New Post Published', $post->post_title);
}
add_action('publish_post', 'notify_on_publish');
Whenever a post is published, this automatically sends an email to the admin. The publish_post action triggers when a post gets published.
3. Create Custom Shortcode
function show_current_year() {
return date('Y');
}
add_shortcode('year', 'show_current_year');
With this, you can write [year] in any post/page and it will automatically display the current year. The Shortcode API lets you add custom dynamic content.
Also Read: API Basics Explained: Endpoints, Requests, Responses & API Keys (With Examples)
How to Use WordPress API Code
There are different methods to use WordPress API code:
1. Theme’s functions.php File
This is the most common method. Paste code in the functions.php file in your active theme’s folder.
![WordPress API vs WordPress REST API: With Examples [2026] 4 wordpress theme editor navigation screenshot](https://apibuddy.net/wp-content/uploads/2024/09/wordpress-theme-editor-navigation-screenshot.webp)
- WordPress Dashboard → Appearance → Theme File Editor
- Select
functions.phpfrom the right side - Paste code and click “Update File”
Please be aware that a minor typo could bring your site down and code may be lost when theme is updated.
2. Child Theme
This is the safest method for theme customization.
- Create a child theme
- Add code in child theme’s
functions.php - Code remains safe even when parent theme is updated
3. Custom Plugin
This is the best practice for reusable code.
- Create a new folder in
wp-content/plugins/(e.g.,my-custom-code) - Create
my-custom-code.phpfile in it - Add plugin header and code in the file:
<?php
/*
Plugin Name: My Custom Code
*/
// Your WordPress API code here
Then activate the plugin from the wordpress dashboard.
4. Code Snippets Plugin
This is the easiest for non-technical users if you are not familiar with editing wodpress files.
![WordPress API vs WordPress REST API: With Examples [2026] 5 Code Snippets Plugin screenshot](https://apibuddy.net/wp-content/uploads/2024/09/Code-Snippets-Plugin-screenshot.webp)
- Install “Code Snippets” plugin
- Dashboard → Snippets → Add New
- Paste code and activate
Code Snippets plugin is best for beginners, custom plugin or child theme for professionals.
Each of these examples demonstrates how to use specific WordPress APIs to extend or interact with WordPress programmatically.
Examples of WordPress REST API
Here are several code examples that demonstrate how to use the WordPress REST API. These examples cover basic tasks such as retrieving posts, creating content, updating data, and deleting resources using HTTP requests.
1. Fetching a Single Post (GET Request)
To get a single post by its ID, use the following endpoint:
GET https://example.com/wp-json/wp/v2/posts/123
Using cURL:
curl -X GET https://example.com/wp-json/wp/v2/posts/123
Example JavaScript:
fetch('https://example.com/wp-json/wp/v2/posts/123')
.then(response => response.json())
.then(post => console.log(post))
.catch(error => console.error('Error:', error));
This fetches the post with the ID 123.
2. Creating a New Post (POST Request)
To create a new post using the REST API, you need to authenticate (e.g., using Basic Authentication or OAuth). Here’s an example with Basic Authentication.
POST https://example.com/wp-json/wp/v2/posts
Using cURL:
curl -X POST https://example.com/wp-json/wp/v2/posts \
-H "Content-Type: application/json" \
-u username:password \
-d '{
"title": "New Post Title",
"content": "This is the content of the new post.",
"status": "publish"
}'
Example JavaScript:
fetch('https://example.com/wp-json/wp/v2/posts', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa('username:password')
},
body: JSON.stringify({
title: 'New Post Title',
content: 'This is the content of the new post.',
status: 'publish'
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
This will create and publish a new post with the specified title and content.
3. Updating an Existing Post (PUT Request)
To update an existing post, send a PUT request with the post ID and the updated data.
PUT https://example.com/wp-json/wp/v2/posts/123
Using cURL:
curl -X PUT https://example.com/wp-json/wp/v2/posts/123 \
-H "Content-Type: application/json" \
-u username:password \
-d '{
"title": "Updated Post Title"
}'
Example JavaScript:
fetch('https://example.com/wp-json/wp/v2/posts/123', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa('username:password')
},
body: JSON.stringify({
title: 'Updated Post Title'
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
This will update the title of the post with the ID 123.
4. Deleting a Post (DELETE Request)
To delete a post, you can send a DELETE request with the post ID.
DELETE https://example.com/wp-json/wp/v2/posts/123
Using cURL:
curl -X DELETE https://example.com/wp-json/wp/v2/posts/123 \
-H "Content-Type: application/json" \
-u username:password
Example JavaScript:
fetch('https://example.com/wp-json/wp/v2/posts/123', {
method: 'DELETE',
headers: {
'Authorization': 'Basic ' + btoa('username:password')
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
This will delete the post with the ID 123.
5. Fetching Categories (GET Request)
To fetch all categories, you can use the following endpoint:
GET https://example.com/wp-json/wp/v2/categories
Using cURL:
curl -X GET https://example.com/wp-json/wp/v2/categories
Example JavaScript:
fetch('https://example.com/wp-json/wp/v2/categories')
.then(response => response.json())
.then(categories => console.log(categories))
.catch(error => console.error('Error:', error));
This will return a list of all the categories available on the WordPress site.
6. Fetching Users (GET Request)
To get the list of users on the WordPress site, use the following endpoint:
GET https://example.com/wp-json/wp/v2/users
Using cURL:
curl -X GET https://example.com/wp-json/wp/v2/users
Example JavaScript:
fetch('https://example.com/wp-json/wp/v2/users')
.then(response => response.json())
.then(users => console.log(users))
.catch(error => console.error('Error:', error));
This returns the user data, such as username, email, and role.
These examples demonstrate how you can interact with the WordPress REST API to manage posts, categories, users, and other content programmatically using HTTP requests. The REST API allows easy access to data from outside WordPress, making it useful for applications, websites, and services that need to interact with a WordPress installation.
Also Read: Perplexity API Pricing Explained: Free Tier, Pay-As-You-Go Costs & Pro Access
How to Use WordPress REST API Code
There are different ways to use WordPress REST API code:
1. Direct URL in Browser
Simply paste the URL in your browser. Quick testing, to check if the API is working or not. Data will appear directly in the browser in JSON format.
https://yoursite.com/wp-json/wp/v2/posts
2. In PHP File (Same WordPress Site)
Add code in your theme or plugin’s PHP file. Fetch data within the WordPress site itself for custom display.
// functions.php or custom template file
<?php
$response = wp_remote_get('https://yoursite.com/wp-json/wp/v2/posts');
$posts = json_decode(wp_remote_retrieve_body($response));
?>
3. External Website/Application
From a different website or application. Display WordPress content on another website, data integration.
// In any PHP file on external-site.com
<?php
$response = file_get_contents('https://yoursite.com/wp-json/wp/v2/posts');
$posts = json_decode($response);
?>
4. JavaScript/React Application
In frontend applications. Single Page Applications (SPA), headless WordPress setup, modern web apps.
fetch('https://yoursite.com/wp-json/wp/v2/posts')
.then(response => response.json())
.then(posts => console.log(posts));
5. Mobile Apps (Android/iOS)
API calls in mobile app development. Mobile apps that fetch content from WordPress.
// React Native example
fetch('https://yoursite.com/wp-json/wp/v2/posts')
.then(response => response.json())
.then(data => setPostsData(data));
6. API Testing Tools
- Postman: For testing API requests
- Insomnia: API development and testing
- cURL: Testing from command line
WordPress API vs WordPress REST API: When to Use Which?
WordPress API Use:
Use traditional WordPress APIs when you’re developing within the WordPress environment (e.g., creating a plugin or theme).
WordPress REST API
Use the WordPress REST API when you need to:
- Access WordPress data from external applications
- Build decoupled or headless WordPress sites
- Create mobile apps that interact with WordPress
- Integrate WordPress with third-party services or applications
| Question | If YES | If NO |
|---|---|---|
| Working inside WordPress only? | WordPress API | REST API |
| Need external/remote access? | REST API | WordPress API |
| Building mobile app? | REST API | WordPress API |
| Customizing theme/plugin? | WordPress API | Could use either |
| Need JSON data format? | REST API | WordPress API |
| Working with JavaScript frameworks? | REST API | WordPress API |
Sometimes you might use both in the same project:
- Use WordPress API to register custom post types
- Use REST API to expose those custom posts to mobile app
// WordPress API: Register custom post type
register_post_type('products', $args);
// REST API will automatically make it available at:
// https://yoursite.com/wp-json/wp/v2/products
Summary
WordPress API and WordPress REST API serve different purposes in WordPress development.
WordPress API works internally within WordPress using PHP hooks and filters. It’s used for building plugins, themes, and customizing WordPress functionality from inside the installation. Perfect for adding features, modifying content, or automating tasks within your WordPress site.
WordPress REST API enables external access to WordPress data through HTTP requests with JSON responses. It’s designed for building mobile apps, headless WordPress setups, modern JavaScript applications, and third-party integrations that need to communicate with WordPress remotely.
The key difference: WordPress API is for internal customization (working inside WordPress), while REST API is for external communication (accessing WordPress from outside). Choose WordPress API when building within WordPress, and REST API when connecting external applications or services to your WordPress site.
It is really a great and useful piece of info. I?¦m satisfied that you shared this useful info with us. Please stay us up to date like this. Thank you for sharing.