Skip to content

Instantly share code, notes, and snippets.

@rwsite
Created August 31, 2018 01:01
Show Gist options
  • Save rwsite/98aacc80a53ec8a4eda25adfbf215ab5 to your computer and use it in GitHub Desktop.
Save rwsite/98aacc80a53ec8a4eda25adfbf215ab5 to your computer and use it in GitHub Desktop.
Adding Content from custom fields to Yoast SEO Analysis Using YoastJS
console.log('script ready');
(function($) {
var MyYoastPlugin = function()
{
YoastSEO.app.registerPlugin('myYoastPlugin', {status: 'loading'});
this.getData();
};
MyYoastPlugin.prototype.getData = function()
{
var _self = this,
$text = $('#rw-product_cat_details');
_self.custom_content = $text.val();
YoastSEO.app.pluginReady('myYoastPlugin');
YoastSEO.app.registerModification('content', $.proxy(_self.getCustomContent, _self), 'myYoastPlugin', 5);
};
MyYoastPlugin.prototype.getCustomContent = function (content)
{
var mceid = $('#rw-product_cat_details textarea').prop('id');
console.log('mceid');
var mycontent = isEditor( mceid ) ? tinymce.get( mceid ).getContent() : content;
return this.custom_content + mycontent + content;
};
/**
* Check if the field is a TinyMCE editor.
*
* @param fieldId The field ID
* @returns boolean
*/
function isEditor( fieldId ) {
return typeof tinymce !== 'undefined' && tinymce.get( fieldId ) !== null;
}
$(window).on('YoastSEO:ready', function ()
{
new MyYoastPlugin();
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment