Meta description of Custom Post Type

#279788
  • Resolved Novato
    Rank Math free

    Hello,

    I am using a Custom Post Type on my site and the main field of that page is coming from the plugin.

    But I want the content inside that to show as the Meta Description of that CPT page.

    Can you please let me know what I want to add under RankMath’s Title & Meta Section for the CPT under this area: Single XYZ – Listing Description

    https://imgur.com/a/wYuT2r8

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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.​

    Novato
    Rank Math free

    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.

    Novato
    Rank Math free

    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.

Viewing 5 replies - 1 through 5 (of 5 total)

The ticket ‘Meta description of Custom Post Type’ is closed to new replies.