Hello,
Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.
Am assuming you mean the select field type in this case. If you have the “Return type” as both value and array then you will still use the same variable as %customfield(fieldname_label)%
.
But please ensure that you are in a position to select multiple values for your choices in this case. You can have this option enabled in your field group options as shown in this screenshot:https://i.rankmath.com/Q5Yeta.
Hope this helps. Please let us know if you have any other questions.
Thank you.
When I select “both(array)” I will get both label and value, how do I get the label instead of the value on seo meta?
Hello,
Thank you for keeping in touch with us.
Unfortunately, returning the array in variables for your meta settings might not be possible to retrieve the label.
You can however make a workaround by modifying our filter and insert it to your theme’s functions.php
file. Here I edited a filter for you to create a custom variable and retrieve the custom field’s label.
add_action( 'rank_math/vars/register_extra_replacements', function(){
rank_math_register_var_replacement(
'shortcode_var_name', [
'name' => esc_html__( 'Author name', 'rank-math' ),
'description' => esc_html__( 'Author description', 'rank-math' ),
'variable' => 'shortcode_var_name', /* the actual variable: %shortcode_var_name% */
'example' => shortcode_var_name_call_back(),
],
'shortcode_var_name_call_back'
);
});
function shortcode_var_name_call_back(){
global $post;
$thefield = get_field_object('jdt_select_label', $post->ID);
return $thefield['label'];
}
In this code, the label name should be called once you include the variable %shortcode_var_name%
in your SEO meta settings. You may edit this code as per your preference.
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Thank you so much! Do you have an in-depth tutorial about creating custom variables or can you tell me where I can find the Rank Math built in variables code, I mean which file? I wanted to create custom variables with parameters also, like variable(par=x) like the customterm().
Hello,
Thank you for keeping in touch with us.
Allow me to check this one with our dev team. We should get back to you with an answer shortly.
Thank you.
Hello,
If you want to check the custom variables created by Rank Math and the source code of them you can find them under the folder: seo-by-rank-math/includes/replace-variables
In that folder, you’ll see a bunch of files with custom variables that we use throughout the plugin.
Let us know if this is the information you were looking after.
Looking forward to hearing back from you.
Hello,
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.