Insert GTIN13 data using Existing Attribute

#392745
  • Resolved Alan Diego Polini
    Rank Math free

    Hi!

    In Google Search Console, warning that GTIN data is not appearing.

    However, I already have an attribute of my products in which the GTIN information is inserted. (it starts with PA_)

    I’ve read in other threads that it’s possible to enter a code so that the data from that field is inserted into the GTIN field of Rank Math.

    I ask for help because I don’t know how to write the code. I’ve already tried other codes informed, replacing only the database term, but it didn’t work.

    Could you please help me?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Prabhat
    Rank Math agency

    Hello,

    Thank you for contacting the support.

    You can modify and add the below filter to the website to add GTIN to the products:

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        if( false !== is_product() ){
    	global $product;
            $gtin = $product->get_attribute( 'attribute-1' );  // Replace 'attribute-1' with attribute name
            $entity['gtin8'] = $gtin;  // Replace 'gtin8' with the required GTIN type.
        }    
        return $entity;
    });

    In the above code, firstly you need to replace replace attribute-1 with the actual attribute name (the slug), and secondly, you can replace gtin8 with the required GTIN type.

    Here’s how you can add the filter:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope this helps.

    Thank you.

    Thanks for your help.
    The code provided in the answer worked perfectly.

    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.

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

You must be logged in to reply to this ticket.