Support Forum
I'm looking to integrate a custom field created using the Meta Box into the schema data generated by the Rank Math SEO plugin. My goal is to use the value of this custom field dynamically in various parts of the schema.
I would like to place a unique placeholder (such as %custom_field%) in Rank Math’s schema settings wherever I want the custom field's value to appear.
Any guidance on this is greatly appreciated!
Hello Eric,
You can follow the Rank Math documentation to create a custom variable https://rankmath.com/kb/variables-in-seo-title-description/#how-to-add-custom-variables
and Meta Box documentation to get a field value by using the helper function rwmb_meta()
https://docs.metabox.io/functions/rwmb-meta/
Note: we don't support the customization code for your specific needs. If you cannot complete the task, we offer a customization service with an extra fee.
Eric, did you ever get this figured out?
Hi Andy,
Thanks for checking in! Yes, I managed to integrate the custom field from Meta Box into the schema data generated by Rank Math SEO plugin following Peter's guidance. It took a bit of tinkering, but I was able to create a custom variable in Rank Math by adding some code to my theme's functions.php
file. This custom variable is now dynamically pulling the value from my custom field created with Meta Box.
Using the rwmb_meta()
function to retrieve the field value was straightforward, thanks to the Meta Box documentation. The real trick was ensuring that the placeholder I set in Rank Math's schema settings matched the custom variable I created. Once everything was correctly set up, the custom field value started appearing dynamically in the schema wherever I used the placeholder.
Although the process was a bit technical, the documentation from both Rank Math and Meta Box was incredibly helpful. I didn’t end up needing the customization service, but it's good to know it's available for more complex tasks.
I appreciate the community's support and hope this helps anyone else trying to achieve something similar!
-Eric
in the case of saving data a custom table? should I also call up the table?
example my table where i save the custom fields is called custom_mb_field
i tried following this guide
/**
* Action: 'rank_math/vars/register_extra_replacements' - Allows you to add extra variables.
* Snippet to register the variable that will return the number of posts in the current term.
*/
add_action('rank_math/vars/register_extra_replacements', function () {
rank_math_register_var_replacement(
'term_count',
[
'name' => esc_html__('Term Count', 'rank-math'),
'description' => esc_html__('Number of posts in the current term', 'rank-math'),
'variable' => 'term_count',
'example' => term_count_callback(),
],
'term_count_callback'
);
});
term_count_callback() function
{
$term = get_queried_object();
return isset($term) ? $term->count : null;
}
available at this link https://rankmath.com/kb/variables-in-seo-title-description/#how-to-add-custom-variables
and I tried saving it inside wpcodebox2 but it always returns the empty field
Hello Christian,
If you use the custom table to save the field value, please follow the documentation
https://docs.metabox.io/extensions/mb-custom-table/#getting-field-value
to get the field value.