Created
February 21, 2019 21:21
-
-
Save nickdavis/2d052d77464bd16b3fe20a5df37c1351 to your computer and use it in GitHub Desktop.
Adding Carbon Fields to Yoast SEO content analysis
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
/** | |
* Adds specified Carbon Field to the Yoast SEO content analysis. | |
* | |
* @link https://return-true.com/adding-content-to-yoast-seo-analysis-using-yoastseojs/ | |
* @link https://kb.yoast.com/kb/can-i-add-data-to-the-page-analysis/ | |
* @link https://github.com/Yoast/YoastSEO.js/blob/master/README.md | |
* @link https://github.com/Yoast/YoastSEO.js/issues/181#issuecomment-163162489 | |
*/ | |
(function($) { | |
var MyYoastPlugin = function() | |
{ | |
YoastSEO.app.registerPlugin('carbonFieldIntroText', {status: 'loading'}); | |
this.getData(); | |
}; | |
MyYoastPlugin.prototype.getData = function() | |
{ | |
var _self = this, | |
$text = $('#carbon-field-7'); | |
_self.custom_content = $text.val(); | |
YoastSEO.app.pluginReady('carbonFieldIntroText'); | |
YoastSEO.app.registerModification('content', $.proxy(_self.getCustomContent, _self), 'carbonFieldIntroText', 5); | |
}; | |
MyYoastPlugin.prototype.getCustomContent = function (content) | |
{ | |
return this.custom_content + content; | |
}; | |
$(window).on('YoastSEO:ready', function () | |
{ | |
new MyYoastPlugin(); | |
}); | |
})(jQuery); |
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
<?php | |
/** | |
* Carbon Fields and Yoast SEO modifications | |
* | |
* @package NickDavis\Theme\Admin | |
* @since 1.0.0 | |
* @author Nick Davis | |
* @link https://iamnickdavis.com | |
* @license GNU General Public License 2.0+ | |
*/ | |
namespace NickDavis\Theme\Admin; | |
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\enqueue_yoast_seo_analysis_carbon_fields_script' ); | |
/** | |
* Adds selected Carbon Fields to Yoast SEO content analysis. | |
* | |
* @since 1.0.0 | |
* | |
* @link https://return-true.com/adding-content-to-yoast-seo-analysis-using-yoastseojs/ | |
* @link https://kb.yoast.com/kb/can-i-add-data-to-the-page-analysis/ | |
* @link https://github.com/Yoast/YoastSEO.js/blob/master/README.md | |
* @link https://github.com/Yoast/YoastSEO.js/issues/181#issuecomment-163162489 | |
*/ | |
function enqueue_yoast_seo_analysis_carbon_fields_script() { | |
wp_enqueue_script( 'yoast-seo-carbon-fields', CHILD_THEME_URL . '/assets/js/admin/yoast-seo-carbon-fields.js', array( 'jquery', 'yoast-seo-admin-script' ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment