Hello,
Thank you for contacting us.
If that is a custom field, please add the field name under Rank Math > Titles & Meta > Post/Page/CPT (where the field is to be used) > Custom Fields.
Once done, you can use the %customfield(field-name)%
variable to get the field’s contents. You need to replace the field-name with the actual name of the field.
Hope this helps.
Thank you.
Okay, I tried doing that as you mentioned with the custom field box and then adding it to the title line. I’m still not getting the expected result. Is there a specific way the custom field needs to be written in the box? See images of how I entered it.
https://ibb.co/FHc1gqf
https://ibb.co/JKzPJyb
Hello,
It seems that you’re checking the Rank Math settings.
Please note that the sample/preview showing in Rank Math > Titles & Meta settings sometimes does not show your actual title/description. You can check the page’s source code or use this tool to verify:
https://heymeta.com
I hope that helps.
Thank you.
Yes, I double checked the source code on the page, even though I added the tag to the title in the settings menu, it does not show it on the page itself. I have made other changes that show up but this field does not show up. And I have confirmed with the plugin developer that the post meta field is the _sku and is on that page. I’m not sure if adding it to that Custom field box isn’t causing the Rank Math to look for the field like it is supposed to?
Hello,
You can try the following code to output the value of that custom field in a variable called %product-sku%
:
// Custom variable for the custom field from the wp_postmeta table
add_action( 'rank_math/vars/register_extra_replacements', function(){
rank_math_register_var_replacement(
'product-sku',
[
'name' => esc_html__( 'Product SKU', 'rank-math' ),
'description' => esc_html__( 'Get the product SKU from database', 'rank-math' ),
'variable' => 'product-sku',
'example' => 'product_sku_callback()',
],
'product_sku_callback'
);
});
function product_sku_callback() {
return get_post_meta(get_queried_object_id(), '_sku', true);
}
If you are not sure how to insert the code on the website please follow the steps illustrated here: https://rankmath.com/kb/wordpress-hooks-actions-filters/
Hope this helps solve your issue.
Don’t hesitate to get in touch if you have any other questions.
Thank-you very much. That is exactly what I needed. It is working now. Thank-you very much.
Hello,
We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.
If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.
If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
Thank you.