Understanding and Using WordPress REST API Endpoint URLs
Content
When working with the WordPress REST API, one common point of confusion is the format of the endpoint URL. Specifically, developers often wonder if the URL structure changes based on their site's permalink settings and which format is the most reliable to use. This guide explains the two primary URL formats and the best practices for accessing the API.
The Two REST API URL Formats
WordPress provides two main ways to construct a REST API endpoint URL:
- Pretty Permalinks (Post name): When your site uses a "pretty" permalink structure (e.g.,
/%postname%/), the API base URL is typically:
https://yoursite.com/wp-json/ - Plain Permalinks: If your site is using the default "plain" permalink setting, the API base URL uses a query parameter:
https://yoursite.com/?rest_route=/
The Universal Solution
Analysis of community support threads confirms a key piece of information: the /?rest_route=/ format is always accessible, regardless of which permalink formatting is set on the site. This makes it a universally reliable method for constructing API requests.
Best Practices for Developers
While you can hardcode the ?rest_route= format, the recommended method for developers writing code within a WordPress environment is to use the built-in rest_url() function. This function automatically generates the correct base URL for the REST API based on the site's current configuration, making your code more robust and future-proof.
Hosting and Firewall Considerations
Access to the REST API is generally available on all standard hostings. It is extremely rare for a firewall to block it, but it is not impossible. If you are unable to access the API using either URL method, you may need to check your hosting provider's security rules or mod_security settings.
Summary
To ensure consistent access to the WordPress REST API:
- For manual testing or direct linking, the
https://yoursite.com/?rest_route=/<endpoint>format is a safe bet that works in all environments. - For development within plugins or themes, always use the
rest_url()function to generate endpoint URLs programmatically.
Related Support Threads Support
-
Notranslate Chromhttps://wordpress.org/support/topic/notranslate-chrom/
-
Automatically format a new hyperlink with title text from the link destinationhttps://wordpress.org/support/topic/automatically-format-a-new-hyperlink-with-title-text-from-the-link-destination/
-
How does G meta Keyword workhttps://wordpress.org/support/topic/how-does-g-meta-keyword-work/
-
[NSFW] Click to link counterhttps://wordpress.org/support/topic/click-to-link-counter/
-
Since when – на вашем языке: Русский (также Lietuvių kalba)???https://wordpress.org/support/topic/since-when-%d0%bd%d0%b0-%d0%b2%d0%b0%d1%88%d0%b5%d0%bc-%d1%8f%d0%b7%d1%8b%d0%ba%d0%b5-%d1%80%d1%83%d1%81%d1%81%d0%ba%d0%b8%d0%b9-%d1%82%d0%b0%d0%ba%d0%b6%d0%b5-lietuviu-kalba/
-
Hook for checking and returning meta value from DBhttps://wordpress.org/support/topic/hook-for-checking-and-returning-meta-value-from-db/
-
Finding a pluginhttps://wordpress.org/support/topic/finding-a-plugin-4/
-
Social Networks Link in Maintenance modehttps://wordpress.org/support/topic/social-networks-link-in-maintenance-mode/
-
Feature Request: Add Custom Languagehttps://wordpress.org/support/topic/feature-request-add-custom-language/
-
Automation of Digital Badges to User account.https://wordpress.org/support/topic/automation-of-digital-badges-to-user-account/
-
Link Field for Javascript Functionshttps://wordpress.org/support/topic/link-field-for-javascript-functions/
-
to make better multilingualhttps://wordpress.org/support/topic/to-make-better-multilingual/
-
Customizing ALL url structures (permalinks) – why is this not in the CORE?https://wordpress.org/support/topic/customizing-all-url-structures-permalinks-why-is-this-not-in-the-core/
-
Translation Credithttps://wordpress.org/support/topic/translation-credit/
-
Enable Multiple Language-Specific Sitemapshttps://wordpress.org/support/topic/enable-multiple-language-specific-sitemaps/
-
REST API endpoint URLhttps://wordpress.org/support/topic/rest-api-endpoint-url/
-
Les Liens – The Linkshttps://wordpress.org/support/topic/les-liens-the-links/
-
Multiple links linking to pdf parts of a pdf doc.https://wordpress.org/support/topic/multiple-links-linking-to-pdf-parts-of-a-pdf-doc/
-
Request | Open Plugin External Links in New Tabhttps://wordpress.org/support/topic/request-open-plugin-external-links-in-new-tab/
-
Support for Meta Descriptions without the need for a pluginhttps://wordpress.org/support/topic/support-for-meta-descriptions-without-the-need-for-a-plugin/
-
Add Language to Pages & Posts toohttps://wordpress.org/support/topic/add-language-to-pages-posts-too/
-
Relative Linkshttps://wordpress.org/support/topic/relative-links-8/
-
API for docking pos system.https://wordpress.org/support/topic/api-for-docking-pos-system/
-
hreflang implementationhttps://wordpress.org/support/topic/hreflang-implementation/
-
AI Content Detectorhttps://wordpress.org/support/topic/ai-content-detector/
-
Virtual Tour – WordPress plugin or external tool inserted in iframehttps://wordpress.org/support/topic/virtual-tour-wordpress-plugin-or-external-tool-inserted-in-iframe/
-
plugins Driver clone uberhttps://wordpress.org/support/topic/plugins-driver-clone-uber/
-
How to Find Dofollow Outbound Links From My Websitehttps://wordpress.org/support/topic/how-to-find-dofollow-outbound-links-from-my-website/
-
URL Objecthttps://wordpress.org/support/topic/feature-requesturl-object/
-
Core Feature: In-built browser to open external links/URLshttps://wordpress.org/support/topic/core-feature-in-built-browser-to-open-external-links-urls/
-
Use of href to redirect to locationhttps://wordpress.org/support/topic/use-of-href-to-redirect-to-location/
-
Custom Meta Tagshttps://wordpress.org/support/topic/custom-meta-tags-3/
-
Customize WordPress page urlshttps://wordpress.org/support/topic/customize-wordpress-page-urls/
-
“Press This” became a plugin but then got removed from Plugins too. So use…?https://wordpress.org/support/topic/press-this-became-a-plugin-but-then-got-removed-from-plugins-too-so-use/
-
wordpress change url slug as page goes downhttps://wordpress.org/support/topic/wordpress-change-url-slug-as-page-goes-down/
-
Plugin: Autolink words in contenthttps://wordpress.org/support/topic/plugin-autolink-words-in-content/