Table of Contents

How to fill the YOAST SEO Meta data when creating a post using API

How to Fill Yoast SEO Meta Data When Creating a Post Using the API As developers integrating with WordPress via its REST API, one of the most common hurdles is...

2026-08-10

How to Fill Yoast SEO Meta Data When Creating a Post Using the API

As developers integrating with WordPress via its REST API, one of the most common hurdles is correctly handling plugin-specific data structures. You want to populate fields like Yoast SEO's meta description, but the direct approach often leads to empty fields. This is a classic example of needing to understand not just what data the endpoint accepts, but how the WordPress backend serializes that data for specific plugins.

This post will break down why your current method might be failing and provide a robust, developer-focused strategy for correctly injecting Yoast SEO metadata into your posts via API calls.

Understanding the Yoast SEO Data Structure

The reason you are likely seeing empty meta descriptions is that while WordPress supports standard meta fields, complex plugin data like Yoast SEO often relies on specific internal hooks or custom field structures that are not directly exposed in the standard post creation payload for simple endpoints.

When dealing with the WordPress REST API, the system expects data to map cleanly to the database schema. Directly injecting a nested structure like 'yoast_meta': {'yoast_wpseo_metadesc': meta_description} often bypasses the necessary serialization hooks that Yoast uses internally to process and save these fields correctly upon post creation.

The Developer Solution: Using Standard Fields and Custom Data

Instead of trying to guess the exact internal structure, the most reliable approach is to leverage the standard WordPress mechanisms or utilize custom fields if you need highly specific SEO control.

Option 1: Relying on Standard Meta Fields (The Simplest Way)

For basic search engine optimization, the standard meta field is usually sufficient for the primary description. If your goal is just to have a meta description visible in the standard WordPress backend, use this structure:

post_data = {
      'title': title,
      'content':  markdown.markdown(content),
      'slug': slug,
      'status': 'publish',
      'meta': {
          'description': meta_description, // Standard WordPress field
      },
      'author': author_id,
      'categories': [category_id],
  }
  

While this populates the basic description, it doesn't necessarily trigger Yoast’s specific SEO scoring unless you are using a custom endpoint designed to handle those fields.

Option 2: Leveraging Custom Fields for Deep Integration (The Robust Way)

For complex integrations where you need Yoast-specific features (like SEO analysis or specific schema markup), the most robust method is to use WordPress's native Custom Fields system, typically managed via Advanced Custom Fields (ACF).

When using an API, instead of trying to push proprietary plugin data directly into the payload, you should: 1. Create a custom field group in ACF for your SEO data (e.g., 'Yoast SEO Data'). 2. Include these custom fields in your API request. 3. When the post is saved, ensure your backend logic handles mapping this incoming data to the correct database meta keys that Yoast expects.

This approach mirrors how large-scale applications—like those built with frameworks such as Laravel—manage complex relational data by enforcing clear boundaries between input and persistence. For instance, understanding how Eloquent models relate to database tables is crucial for building reliable API interactions, much like understanding the internal structure of a plugin like Yoast.

Best Practice Implementation Example

If you must inject the specific Yoast meta description via API, ensure your endpoint and the receiving system are set up to handle it as a custom field, rather than relying on direct nesting:

post_data = {
      'title': title,
      'content':  markdown.markdown(content),
      'slug': slug,
      'status': 'publish',
      # Use a dedicated custom field key if you are using ACF or similar structures
      'seo_meta_description': meta_description, 
      'author': author_id,
      'categories': [category_id],
  }
  
  # Send this data to the /wp-json/wp/v2/posts endpoint
  

By structuring your API data around explicitly defined fields (either standard or custom), you ensure that the data flows through the established WordPress hooks and validation layers. This prevents the issue of empty fields by respecting the data workflow rather than attempting to override internal plugin serialization directly.

Conclusion

When interacting with dynamic systems like WordPress via an API, treat plugin-specific metadata as specialized data points. Avoid direct nesting of proprietary keys unless you have explicit documentation confirming that the endpoint supports it. By structuring your payloads to use standard meta fields or established custom field structures, you build a far more stable and maintainable integration layer. For scalable backend development, understanding these serialization boundaries is key to building reliable services, much like ensuring data integrity in any large application architecture.

Stefan

Stefan

SEO engineer and Laravel developer. Building tools to help Laravel applications rank higher in search results.

Share this article

Back to Blog