Hello,
Thank you for contacting the support, and sorry for any inconvenience that might have been caused due to that.
I’m not quite sure whether I fully understand the question. But I’ll do my best and please let me know if I misunderstood.
The default %excerpt%
variable from Rank Math should be able to help you add the content from your CPT’s content editor to your meta description.
If you are using custom fields, you can use the variable %customfield(field_name)%
.
Hope this helps solve your issue.
Don’t hesitate to get in touch if you require any further assistance.​
Hello Jeremy,
Thank you for getting back to me.
I have already tried those before posting but I think I am not doing it correctly.
Can you please find the details in the Sensitive area?
Hello,
It seems this field is created from the plugin you used to create its CPT.
In this case, you would need to create a custom Rank Math variable and contact the plugin developer and ask if how would you retrieve the description from the field using PHP.
This is how the filter would look like:
/**
* Action: 'rank_math/vars/register_extra_replacements' - Allows adding extra variables.
* Snippet to register variable that will return all terms in custom taxonomy
*/
add_action( 'rank_math/vars/register_extra_replacements', function(){
rank_math_register_var_replacement(
'new_var_name', [
'name' => esc_html__( 'Author name', 'rank-math' ),
'description' => esc_html__( 'Author description', 'rank-math' ),
'variable' => 'new_var_name', /* the actual variable: %new_var_name% */
'example' => new_var_name_call_back(),
],
'new_var_name_call_back'
);
});
function new_var_name_call_back(){
global $post;
return get_field('my_field_name', $post->ID); /* GET THE FIELD NAME OF POLITICIAN DESCRIPTION */
}
Insert this code in your theme’s functions.php file, then, you can make use of the variable %new_var_name% to be added to your SEO meta description.
Looking forward to helping you with this one.
Hello,
Even if I add the code you share, without changing it to anything (based on my post type), the code is still showing an error n the last but one line.
Can you please check that?
Thank you.
Hello,
The filters we provide are just placeholders to show you the basics of modifying Rank Math’s functionality. You would need to further modify this as per your requirement.
Specifically for this filter code, you need to focus on this part:
...
return get_field('my_field_name', $post->ID);
...
This would require you to check how the “Politician Description” field is registered on your website. If this is a standard custom field, you can use the function get_field()
and add the name of the field. To further identify how to retrieve this field. I would recommend contacting the plugin support of this CPT to help you what specific name of the field this is.
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.