I am using the WordPress REST API (wp-json/wp/v2/posts
) to publish posts. The request works, but when I analyze the post in Yoast SEO, it says I need to add a meta description and a focus keyword (target query). I couldn’t find any documentation on how to include these in the API request body.
Here is my current API request body:
{
"title": "My Post Title",
"content": "The content of my post"
}
How can I include the Yoast SEO meta description and focus keyword in this request so that they are correctly recognized by Yoast SEO?
I expected to include meta description and focus keyword fields directly in the API request, similar to how other post data (title
, content
) is added.
I tried adding custom fields like yoast_wpseo_metadesc
and yoast_wpseo_focuskw
inside the metadata or meta fields but it didn’t work, and Yoast SEO still says those fields are missing. How can I properly include the meta description and focus keyword when creating a post via the WordPress REST API?
2
Answers
You need to provide data of
yoast_wpseo_metadesc
andyoast_wpseo_focuskw
usingmeta_input
which is the standard for most custom fields.I believe including these to your current API request body should fix the issue.
You can try this code:
Note the underscore at the beginning of the meta_key. So, they are _yoast_wpseo_metadesc instead of yoast_wpseo_metadesc, and _yoast_wpseo_focuskw instead of yoast_wpseo_focuskw.