API Support for Adding SEO Metadata and Yoast Blocks Programmatically
-
Hello Yoast Support Team,
We are working on programmatically adding SEO metadata and using Yoast features via the WordPress REST API. However, we are encountering challenges when trying to set the following metadata fields:
- Main Focus Keyword
- Related Synonyms
- Related Phrase
- Meta Description
- SEO Title
- Index/Table of Contents (using the Yoast “Table of Contents” block)
We would like to know the exact field names and data structures used by Yoast to programmatically add these metadata and blocks during post creation or update.
For example, we have tried setting
_yoast_wpseo_focuskw,_yoast_wpseo_metadesc, and_yoast_wpseo_titlein themetafield of the REST API payload, but some fields do not work as expected or are not saved correctly. Additionally, we are unable to insert the “Table of Contents” block dynamically.Could you please provide us with documentation or guidance on how to:
- Add the metadata fields mentioned above.
- Insert the Table of Contents block programmatically.
Thank you for your assistance.
Best regards,
Giuseppe
-
Hi @peppe69
For Meta Description, SEO Title: you can follow the developer article from here and here.
Typically code snippets are added to your theme’s functions.php file. If you’re unfamiliar with using code snippets, we’d like to refer you to the WordPress documentation on how to use a filter.
We recommend creating regular backups of your site and database for your site’s health and safety. A backup is crucial before making important changes on your website and provides you with a safety net if something were to go wrong. Learn more about the benefits of regular backups.
Focus keyword, Related Keyphrase and Synonyms:
We don’t have API to add these.
The objective is to help you optimize the content using the focus keyphrase. So you will edit each individual post or page, add a focus keyphrase, and then work on the feedback in the content analysis provided by Yoast SEO. Since the focus keyphrase, related keyphrase or keyphrase synonym do not output in the page source, adding these through an API won’t be useful if you don’t edit the post itself.
Table of Contents:
This forum is reserved for supporting the free version of Yoast SEO. As the Table of Content is about a premium plugin, this thread has been marked as resolved per the forum guidelines.
This thread was marked resolved due to a lack of recent activity. The original poster can change the status to
Not Resolvedto re-open the issue or open a new topic.If you are not the original poster but have a similar issue, please open a new topic.
The topic ‘API Support for Adding SEO Metadata and Yoast Blocks Programmatically’ is closed to new replies.