skip to Main Content

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


  1. You need to provide data of yoast_wpseo_metadesc and yoast_wpseo_focuskw using meta_input which is the standard for most custom fields.

    I believe including these to your current API request body should fix the issue.

    {
      "title": "My Post Title",
      "content": "The content of my post",
      "meta_input": {
        "yoast_wpseo_metadesc": "This is the meta description for the post.",
        "yoast_wpseo_focuskw": "this is the focus keyword."
      }
    }
    
    Login or Signup to reply.
  2. You can try this code:

    'body' => array(
                    'title': 'My Post Title',
                    'content': 'The content of my post',
                    'meta' => array(
                        // note the beginning underscore
                        '_yoast_wpseo_metadesc' => 'The SEO description',
                        '_yoast_wpseo_focuskw' => 'The SEO focus keywords',
                    ),
                ),
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search