Your Core Idea (Improved & Clarified)

Key Corrections & Clarifications

  1. Get Pages + SEO Data
  • In WordPress, the SEO title & meta description are usually stored by an SEO plugin like Yoast SEO, Rank Math, or All in One SEO. These are custom fields, not part of the default post title.

  • So your workflow must read:

    • Page URL (slug or permalink)

    • Page’s focus keyword (if stored — e.g., Yoast stores it as _yoast_wpseo_focuskw)

    • SEO title (_yoast_wpseo_title)

    • SEO description (_yoast_wpseo_metadesc)

  1. Correction: Make sure your API calls pull the custom fields for SEO data, not just the default post title/description.

  2. Shortlist Pages

  • Filter only the pages where SEO title and/or SEO meta description is empty.

  • If the focus keyword is empty too, you might decide to skip that page or use a fallback keyword derived from the URL or content.

  1. Generate Title & Description
  • For each page with missing fields, send to ChatGPT:

    • Focus keyword

    • URL slug

    • Optional: page content or H1 for better context.

  • Prompt ChatGPT to generate a clear SEO title & meta description within best practices (e.g., title ~ 50-60 chars, description ~ 150-160 chars).

  1. Publish Updates
  • Use the WordPress REST API to update the post meta for each page.

  • You’ll need to use the update meta endpoint for custom fields.

  1. Logging & Error Handling
  • Keep logs so you know which pages were updated.

If ChatGPT fails to generate a value, skip or flag for manual review.