I have recently developed a WordPress plugin that utilizes Open AI to generate descriptions and other data for products. One of the challenges I’m facing is integrating the generated meta descriptions into the Yoast SEO plugin.
I am looking for guidance on how to programmatically update the meta description field of the Yoast SEO plugin with the generated meta description data. I have been trying to find the appropriate selector or method to achieve this, but so far, I haven’t been successful.
If anyone has experience working with the Yoast SEO plugin or has encountered a similar issue, I would greatly appreciate any insights or suggestions on how to accomplish this task.
The code which i currently trying is :
// Send the cURL request for generating meta description
var metaDescRequest = new XMLHttpRequest();
metaDescRequest.open('POST', apiLink, true);
for (var header in headers) {
metaDescRequest.setRequestHeader(header, headers[header]);
}
metaDescRequest.onreadystatechange = function() {
if (metaDescRequest.readyState === 4 && metaDescRequest.status === 200) {
var metaDesc = JSON.parse(metaDescRequest.responseText).choices[0].text;
console.log(metaDesc);
jQuery('#yoast-meta-description').val(metaDesc); // Update the Yoast SEO plugin meta description field with the generated meta description
}
};
metaDescRequest.send(metaDescRequestData);
I can see the generated data in the console but not displaying in the meta description field of Yoast SEO plugin
Thank you for your time and assistance!
Open AI , WordPress Documentation , Stack Overflow
I just wanna get any selector for the meta description to use in my Open AI request
2
Answers
Yes the issue is solved i add this code to the request to click the insert variable first : // Simulate a click event on the "Insert variable" button var insertVariableButton = document.querySelector('.yst-replacevar__button-insert'); insertVariableButton.click();