Created
August 31, 2018 01:01
-
-
Save rwsite/98aacc80a53ec8a4eda25adfbf215ab5 to your computer and use it in GitHub Desktop.
Adding Content from custom fields to Yoast SEO Analysis Using YoastJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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