Yoast SEO 14.0: REST API endpoint
With Yoast SEO 14.0 we’re introducing lots of new goodies. One of them is a Yoast SEO REST API endpoint that’ll give you all the metadata you need for a specific URL. This will make it very easy for headless WordPress sites to use Yoast SEO for all their SEO meta output.
There are two ways of using this: through its inclusion in the normal WP REST API responses and through our own endpoint.
Inclusion in WP REST API responses
When you’re retrieving a post like so:
https://example.com/wp-json/wp/v2/posts/1
Or like this:
http://example.com/wp-json/wp/v2/posts?slug=hello-world
You’ll receive a normale WP REST API response, with an additional field: yoast_head
. This additional field will contain a blob with all the necessary meta tags for that page. This works for the posts
, pages
, categories
, tags
and all custom post types and custom taxonomies.
For post type archives, when you query the types
endpoint the meta is included there, also on the yoast_head
field. If it is not there, the post type does not have a post type archive enabled.
Yoast SEO REST API syntax
The syntax is very simple, you just GET
to /wp-json/yoast/v1/get_head?url=
with the proper URL, for example:
https://example.com/wp-json/yoast/v1/get_head?url=https://example.com/hello-world/
This will return the following:
{ "head": "the complete, escaped, <head> output for Yoast SEO", "status": 200, }
The head
contains the complete meta output for the page. This means the Yoast SEO REST API output contains everything:
- The title
- The meta description, if you have one
- Robots meta tags
- The canonical URL
- Our Schema output
- OpenGraph meta data
- Twitter meta data
The API returns 404
for an existing page?
If the status
is not 200
but you’re certain the page exists, you’ll need to make sure your site is completely indexed. Just hitting save on the backend should save the post or page to the Indexables database. Note that Yoast SEO will return a head
for other statuses too, so you can use the output on, for instance, 404
pages.
If you have a notice in your site’s admin about indexing your site: please run that index process if you intend to rely on this API.
I don’t want this API on my site!
You can easily disable this API by going to SEO – General – Features and disabling the feature toggle.
Headless WordPress and Yoast SEO
With this Yoast SEO REST API endpoint we hope to support those people building headless WordPress sites a lot better. But we’d love to hear from you if you’re currently building headless WordPress sites. Is this useful to you? Would you like to see changes? Let us know in the comments!
Coming up next!
-
Event
WordCamp Netherlands 2024
November 29 - 30, 2024 Team Yoast is at Sponsoring WordCamp Netherlands 2024! Click through to see who will be there, what we will do, and more! See where you can find us next » -
SEO webinar
Webinar: How to start with SEO (November 19, 2024)
19 November 2024 Learn how to start your SEO journey the right way with our free webinar. Get practical tips and answers to all your questions in the live Q&A! All Yoast SEO webinars »
9 Responses to Yoast SEO 14.0: REST API endpoint