This article shows you how to create custom API endpoints in WordPress to share your business data with other websites or apps.
What Are Custom Endpoints
Custom endpoints are special web addresses that return your website data in a structured format. For example, you might create an endpoint at yoursite.com/wp-json/custom/v1/opening-hours that shows your business hours in a format other websites can use.
This is useful if you want to share product information, staff details, or business hours with booking systems, mobile apps, or other websites.
Method 1: Using Your Theme's Functions File
- Log into your WordPress admin dashboard
- Go to Appearance > Theme Editor
- Click on "functions.php" from the file list
- Add this code at the end of the file (before the closing ?> tag if one exists):
// Add custom endpoint for business hours
function add_business_hours_endpoint() {
register_rest_route('custom/v1', '/business-hours/', array(
'methods' => 'GET',
'callback' => 'get_business_hours_data',
'permission_callback' => '__return_true',
));
}
add_action('rest_api_init', 'add_business_hours_endpoint');
// Function to return your business hours
function get_business_hours_data() {
$hours = array(
'monday' => '9:00 AM - 5:00 PM',
'tuesday' => '9:00 AM - 5:00 PM',
'wednesday' => '9:00 AM - 5:00 PM',
'thursday' => '9:00 AM - 5:00 PM',
'friday' => '9:00 AM - 5:00 PM',
'saturday' => 'Closed',
'sunday' => 'Closed'
);
return $hours;
}
- Click "Update File"
- Test your endpoint by visiting yoursite.com/wp-json/custom/v1/business-hours in your web browser
Method 2: Using a Child Theme (Recommended)
If you update your theme, changes to functions.php will be lost. A child theme protects your customizations.
- Create a new folder in /wp-content/themes/ called "yourtheme-child"
- Create a file called "style.css" with this content:
/*
Theme Name: Your Theme Child
Template: your-parent-theme-folder-name
*/
- Create a "functions.php" file and add your endpoint code from Method 1
- Go to Appearance > Themes and activate your child theme
For more information about child themes, see Understanding WordPress Child Themes.
Testing Your Custom Endpoint
Once created, you can test your endpoint by:
- Opening yoursite.com/wp-json/custom/v1/business-hours in your web browser
- You should see your data displayed in JSON format
- Other websites and apps can now access this data automatically
Adding Authentication (Optional)
If you want to restrict access to your endpoint, replace 'permission_callback' => '__return_true' with a custom function that checks for proper authentication.
If you're still stuck with creating custom endpoints, contact Web60 support for assistance.
FAQ
Q: Will my custom endpoints break if I update WordPress?
A: No, WordPress updates won't affect your custom endpoints. However, theme updates will remove code from functions.php unless you use a child theme.
Q: Can I create endpoints that accept data from other websites?
A: Yes, change the 'methods' parameter from 'GET' to 'POST' and add code to handle incoming data. You'll also need proper authentication for security.
Q: How do I find the URL of my custom endpoint?
A: Your endpoint URL follows this pattern: yoursite.com/wp-json/namespace/version/route. In our example, it's yoursite.com/wp-json/custom/v1/business-hours.
Q: Can I see all available endpoints on my website?
A: Yes, visit yoursite.com/wp-json/ to see a list of all REST API endpoints available on your WordPress site.
Q: Do custom endpoints work with caching plugins?
A: Most caching plugins exclude REST API endpoints automatically. If you have caching issues, add your endpoint URLs to your caching plugin's exclusion list.
Q: Can I remove WordPress's default REST API endpoints?
A: Yes, but this isn't recommended as many plugins rely on them. If needed for security, use a plugin to disable specific endpoints rather than removing the entire REST API.
Q: What's the difference between REST API and custom post types?
A: Custom post types store data in your WordPress database, while REST API endpoints provide a way to share that data with external systems. You often use both together.
Last updated: 1 March 2026