In this tutorial, you will learn how to integrate Custom fields present in your theme or plugin with the Rank Math SEO plugin.
Using this content analysis API, Rank Math will start analyzing data present in these fields.
Steps to register custom fields in Rank Math’s content analysis API:
1 Create a .js File
Create a new JS file in your Plugin or Theme and add the content analysis API related code in it. Make sure to use
wp_enqueue_script( 'rank-math-integration', DIR . '/js/rank-math-integration.js', [ 'wp-hooks', 'rank-math-analyzer' ], false, true );
2 Registering a plugin/theme
Register your theme or plugin to the Rank Math Content analysis API using below code:
RankMathApp.registerPlugin( 'plugin-name' );
3 Filters to analyze data
Rank Math supports 2 filters to analyze title and content. Following is a syntax to add filter:
wp.hooks.addFilter( 'rank_math_title', 'plugin-name', callback_function_to_fetch_title ) // This will hook into title analysis data. wp.hooks.addFilter( 'rank_math_content', 'plugin-name', callback_function_to_fetch_content ) // This will hook into content analysis data.
4 Function to reload the data
It is recommended to preload as little data as possible to minimize client-side memory usage. If you need to dynamically fetch more data in the process of content creation, then you can use
RankMathApp.reloadPlugin( 'plugin-name' ) function to reload the content analysis. You can also use this function to reload the analysis when any custom field data is changed.
Was this article helpful?
Still need help?
Submit Your Question
Please give us the details, our support team will ge back to you.