'Using the Yoast API on Wordpress.com
We have a headless Wordpress CMS hosted on wordpress.com, and I am having trouble retrieving Yoast SEO tags using the Wordpress API.
The vanilla Wordpress API uses URLs like so:
https://example.com/wp-json/wp/v2/posts/1
but on sites hosted on wordpress.com they are rather different:
public-api.wordpress.com/rest/v1.1/sites/example.wordpress.com/posts/1
I have two possibly-related issues:
- When querying the main API, the additional Yoast field described here is not included.
- When trying to query Yoast directly, I do not know how to transform Yoast’s API URLs to the wordpress.com structure.
I believe solving either of the issues would be enough for us to get the tags needed. We’re using Yoast 18.0, the Yoast output does appear in directly-rendered pages, and the Yoast REST API head endpoint is switched on in settings.
Solution 1:[1]
I have been able to solve this on our production site very simply: the normal API paths do in fact work (at least the /v2/ paths) for our production site.
It seems that the path transformation only applies to the free/cheaper hosting packages on wordpress.com. We are using a free site as an integration testing target so in fact this only fails in testing, not in production with a paid wordpress.com package.
Presumably this is because the cheaper packages are all on some kind of shared instance: when we initially upgraded it did not help, but when we installed Yoast it moved us to a different subdomain and the normal API paths started working. I guess at this point we had been moved to a dedicated instance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Leo |
