-
Hi, how do I update the Rank Math Title and Focus Keyword via the REST API?
-
Hello, I’m sorry for the inconvenience. To update the Rank Math Title and Focus Keyword via the REST API, you can send a GET request to our REST API endpoint for a specific URL. You can use the
getHead
REST endpoint, followed by the URL of the webpage. Here is an example of how to create a request:https://your-domain.com/wp-json/rankmath/v1/getHead?url=https://your-domain.com/hello-world
Replace
your-domain.com
with your website’s domain andhttps://your-domain.com/hello-world
with your URL. The data will be returned in a JSON format that contains thehead
which includes the HTML tags added by Rank Math.You can then use this data in your favorite front-end web app and still take advantage of Rank Math’s on-page optimization.
If you encounter any issues accessing the REST endpoint, you may need to whitelist the REST API endpoint in your firewall. If you’re using Wordfence or Cloudflare, you can follow our dedicated tutorials to whitelist Rank Math’s REST API endpoints.
For more details, you can refer to our guide on Headless CMS Support in Rank Math.
If you have any further questions or need assistance with this, please feel free to ask.
Sources:
How to Automate the Insertion of Focus Keyword » Rank Math
How to Enable Headless CMS Support in Rank Math? » Rank Math
How to Make Your Theme Rank Math Compatible » Rank Math
Bulk Editing Options in the Rank Math SEO PluginHi, I know how to GET the data but I want to POST or PATCH the data.
Hello,
You can use the following meta keys to add the metadata using the API:
rank_math_title rank_math_description rank_math_focus_keyword
Please make sure that the meta keys are registered inside the postmeta table.
You can learn how to register the meta key in this example here: https://wordpress.stackexchange.com/questions/380513/add-post-meta-fields-when-creating-a-post-using-wordpress-rest-api
Hope that helps.
Thank you.
which code am I supposed to use?
I really dont want to change to Yoast but might have to since they have the meta API ready to go.
Hello,
We currently don’t have a Rest API to change the meta programmatically from your end, instead, you can make use of WordPress’s built-in functionality
update_post_meta()
. You can check more of that here: https://developer.wordpress.org/reference/functions/update_post_meta/Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.
The ticket ‘REST API’ is closed to new replies.