Open Boryenko opened 4 years ago
I've just discovered this issue this morning and from the Yoast documentation have put this together which I've put in admin.js instead of the content recommend by this plugin. You can actually just enqueue some admin Javascript yourself and remove the plugin completely with this solution.
This code is my fix. Please note that I give every Carbon Field Gutenberg block wrapper a class of .cf-blocks which is what I've used to grab all the content and feed it into Yoast.
`/ global YoastSEO /
class MyCustomDataPlugin { constructor() { // Ensure YoastSEO.js is present and can access the necessary features. if ( typeof YoastSEO === "undefined" || typeof YoastSEO.analysis === "undefined" || typeof YoastSEO.analysis.worker === "undefined" ) { return; }
YoastSEO.app.registerPlugin("MyCustomDataPlugin", { status: "ready" });
this.registerModifications();
}
/**
@returns {void} */ registerModifications() { const callback = this.addContent.bind(this);
// Ensure that the additional data is being seen as a modification to the content. YoastSEO.app.registerModification( "content", callback, "MyCustomDataPlugin", 10, ); }
/**
@returns {string} The data string parameter with the added content. */ addContent(data) { var $blocks = jQuery(".cf-blocks");
$blocks.each(function () { data += jQuery(this).html(); });
return data; } }
/**
Developer documentation from Yoast this was based on: https://developer.yoast.com/customization/yoast-seo/adding-custom-data-analysis/
No errors in console connected with it