Using GTIN from another meta key for rich snippet

#301868
  • Resolved Beauty Crush
    Rank Math free

    I am a wordpress novice so please excuse me if this is a poorly structured question.

    I was supplied the below code to use SKU as the GTIN for rich snippets, which was working great.

    add_filter( “rank_math/snippet/rich_snippet_product_entity”, function( $entity ) {
    $entity[‘gtin13’] = $entity[‘sku’];
    return $entity;
    });

    I now have a new field for GTIN, which is in the wp_postmeta table of WordPress database using product ID as post_id, with these meta_key values “_cr_gtin”

    Can you please help me update the above code to use this new “_cr_gtin” field for GTIN in rankmath?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting Rank Math support today and bringing your concern to our attention.

    Since the field data will be coming from your postmeta table, you can make use of this filter instead:

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    	$entity['gtin13'] = get_post_meta(get_queried_object_id(), '_cr_gtin', true);
    	return $entity;
    });

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Thanks so much Jeremy.

    How do I test if this filter worked for updating the rich snippet with the new GTIN field?

    Hello,

    You may test your page by submitting it to Google’s Rich Result Test. Check if the new GTIN property and its value are correctly added to your schema structure.

    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 3 replies - 1 through 3 (of 3 total)

The ticket ‘Using GTIN from another meta key for rich snippet’ is closed to new replies.