Exclude local SEO from product pages

#389299
  • Resolved JJ
    Rank Math free

    Hi,

    Is there a way to exclude local SEO information from product pages? We have Woocommerce shop and lots of product pages and we use Rank Maths WoocommerceProduct schema on those. I just don’t want organization properties to be implemented on every product page.

    Another questions is about variable products on Rank Maths WoocommerceProduct schema. Is there a way to add variable product attributes to offer property? All data on offer properties are now identical except availability is InStock or OutOfStock. In other words there is not unique data that separates from others Offers.

    Thanks in advance,
    Novice Advertiser

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

    Thank you for contacting Rank Math support, and sorry for any inconvenience that might have been caused due to that.

    If you wish to remove the organization property to all of your products, you may need to make use of this filter code:

    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    	if ( ! is_product() || ! isset( $data['publisher'] ) ) {
    		return $data;
    	}
        
        unset( $data['publisher'] );
    	unset( $data['place'] );
        return $data;
    }, 99, 2);

    As for the product’s availability in each variation, you may need to apply this filter code as well:

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        if ( ! is_product() ) {
            return $entity;
        }
        
        $product = wc_get_product( get_the_ID() );
        if ( ! $product->is_type( 'variable' ) ) {
            return $entity;
        }
        
        $variations = $product->get_available_variations();
    
        if ( ! empty( $variations ) ) {
            $offers = [];
            foreach ( $variations as $variation ) {
                $price_valid_until = get_post_meta( $variation['variation_id'], '_sale_price_dates_to', true );
                $offers[] = [
    				'@type'           => 'Offer',
    				'description'     => strip_tags( $variation['variation_description'] ),
    				'price'           => $variation['display_price'],
    				'priceCurrency'   => get_woocommerce_currency(),
    				'availability'    => $variation['is_in_stock'] ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock',
    				'priceValidUntil' => $price_valid_until ? date_i18n( 'Y-m-d', $price_valid_until ) : '2025-12-31',
    				'url'             => $product->get_permalink(),
    			];
            }
        }
        
        $entity['offers'] = $offers;
        
        return $entity;
    } );

    The code above allows you to add the Offers individually for your variant type products.

    You may refer to this guide as well on how to apply the filter code on your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/

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

    JJ
    Rank Math free

    Hi Jeremy,

    Thanks for the super fast reply and support! Ill try those filters asap.

    Cheers,
    Novice Advertiser

    Hello,

    Let us know how that goes. Looking forward to hearing back from you.

    Thank you.

    JJ
    Rank Math free

    Hi again,

    Organization filter works fine and thanks for that!

    But I think you misunderstood my second question. Probably my fault, my english is not so great =)

    Let me try explain more better now..

    When there is variable product and many variations, lets say 5 different colors and 5 different sizes. When WoocommerceProduct scema builds JSON-LD Code there is many identical offers as in the example below. I have blurred urls they are working just fine.


    {
    “@type”: “Offer”,
    “price”: 16.5,
    “priceCurrency”: “EUR”,
    “availability”: “https://schema.org/OutOfStock”,
    “itemCondition”: “NewCondition”,
    “priceValidUntil”: “2023-12-31”,
    “url”: “https://***.***/****/”
    },
    {
    “@type”: “Offer”,
    “price”: 16.5,
    “priceCurrency”: “EUR”,
    “availability”: “https://schema.org/OutOfStock”,
    “itemCondition”: “NewCondition”,
    “priceValidUntil”: “2023-12-31”,
    “url”: “https://***.***/****/”
    },
    {
    “@type”: “Offer”,
    “price”: 16.5,
    “priceCurrency”: “EUR”,
    “availability”: “https://schema.org/InStock”,
    “itemCondition”: “NewCondition”,
    “priceValidUntil”: “2023-12-31”,
    “url”: “https://***.***/****/”
    },
    {
    “@type”: “Offer”,
    “price”: 16.5,
    “priceCurrency”: “EUR”,
    “availability”: “https://schema.org/InStock”,
    “itemCondition”: “NewCondition”,
    “priceValidUntil”: “2023-12-31”,
    “url”: “https://***.***/****/”
    },
    {
    “@type”: “Offer”,
    “price”: 16.5,
    “priceCurrency”: “EUR”,
    “availability”: “https://schema.org/InStock”,
    “itemCondition”: “NewCondition”,
    “priceValidUntil”: “2023-12-31”,
    “url”: “https://***.***/****/”
    }
    … and so on.

    Like you see there is no unique data that distinguishes offer from others.

    So my question is there a way to add like sku property to every offer and even better if you could add colors and sizes also. I dont know whats the proper way to add those propertys but i mean like..

    “sku”: “product-1234”,
    “color”: “Red”,
    “size”: “XL”,

    Thanks,
    Novice Advertiser

    Hello,

    Please use the following filter to add the SKU and color to the product variations:

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        if ( ! is_product() ) {
                return $entity;
        }
    
        $product = wc_get_product( get_the_ID() );
        if ( ! $product->is_type( 'variable' ) ) {
                return $entity;
        }
    
        $variations = $product->get_available_variations();
        if ( ! empty( $variations ) ) {
                $offers = [];
                foreach ( $variations as $variation ) {
                        $price_valid_until = get_post_meta( $variation['variation_id'], '_sale_price_dates_to', true );
                        $offers[] = [
                                '@type'           => 'Offer',
                                'description'     => strip_tags( $variation['variation_description'] ),
                                'price'           => $variation['display_price'],
                                'priceCurrency'   => get_woocommerce_currency(),
                                'availability'    => $variation['is_in_stock'] ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock',
                                'itemCondition'   => 'NewCondition',
                                'priceValidUntil' => $price_valid_until ? date_i18n( 'Y-m-d', $price_valid_until ) : '2025-12-31',
                                'url'             => $product->get_permalink(),
                                'sku'             => $variation['sku'],
                                'color'           => $variation->get_attribute( 'pa_color' ) //name of the attribute
                                'size'            => $variation->get_attribute( 'pa_size' ) //name of the attribute
                        ];
                }
        }
    
        $entity['offers'] = $offers;
    
        return $entity;
    } );

    Hope this helps. Let us know if you need any other assistance.

    JJ
    Rank Math free

    Hi there again,

    I tried filter you send. Sku part works flawlessly if I take away color and size lines. If I add those lines WooCommerce Product schema doesn’t generate JSON-LD Code at all.

    {
    “@context”: “https://schema.org”,
    “@graph”: “”
    }

    BTW. You have to change “;” at the end of lines (color and size) to “,” otherwise it crashes.

    ‘sku’ => $variation[‘sku’],
    ‘color’ => $variation->get_attribute( ‘pa_color’ ); //name of the attribute
    ‘size’ => $variation->get_attribute( ‘pa_size’ ); //name of the attribute

    ‘sku’ => $variation[‘sku’],
    ‘color’ => $variation->get_attribute( ‘pa_color’ ), //name of the attribute
    ‘size’ => $variation->get_attribute( ‘pa_size’ ), //name of the attribute

    Hello,

    Please change those two lines with the ones given below:

     'color'           => $variation['attributes']['attribute_pa_color']
     //name of the attribute
      'size'            => $variation['attributes']['attribute_pa_size']
     //name of the attribute

    Hope this helps. Let us know if you need any other assistance.

    JJ
    Rank Math free

    Hello,

    I changed those lines. Now it generates JSON-LD Code, but property values are null. I have tried with attribute name and slug but no change.

    {
    “@type”: “Offer”,
    “price”: ***,
    “priceCurrency”: “EUR”,
    “availability”: “https://schema.org/InStock”,
    “itemCondition”: “NewCondition”,
    “priceValidUntil”: “2025-12-31”,
    “url”: “https://***”,
    “sku”: “***”,
    “color”: null,
    “size”: null
    },

    Nigel
    Rank Math business

    Hello,

    Please create a backup of your current filter function by copying it and pasting in on https://pastebin.com. Next, replace your current filter with the one I have pasted on the following page: https://pastebin.com/QnC823cb

    The linked snippet above was working for me.

    Note: I have removed the schema from the sensitive data as it was making the ticket difficult to read.

    Hope that helps. Please let us know if you have questions.

    JJ
    Rank Math free

    Hi there,

    Now its working! It was my bad. I had wrong attribute names. I tried real attribute names like ‘Koko’ and slug ‘koko’. I didn’t understand that the attribute name needs to be looked from the database. In my case, the correct attribute names were as below..

    ‘color’ => $variation[‘attributes’][‘attribute_pa_vari’],
    ‘size’ => $variation[‘attributes’][‘attribute_pa_koko’]

    I’m sorry but now I have an additional question =D

    There are some products that do not have a size at all or vice versa. Is there a way to check it before adding those lines? Now if there is no color attribute for example it’s shown as ‘null’ as below.

    “color”: null,
    “size”: “37”

    Thanks for the good plugin and support!

    Hello,

    Please replace the filter that you are using with this one: https://pastebin.com/RUcAU0wZ

    Hope this helps. Let us know if you need any other assistance.

    Thanks.

    JJ
    Rank Math free

    Now it works perfectly! There were minor bugs in the latest pastebin code but I got them fixed. Such as the ‘ character was missing and the attribute names was incorrect in the IF statement.

    Thank you very much for your support!

    By the way, we have Rank Math PRO version. However, it’s nice to see that Rank Math FREE support is also this good.

    Hello,

    Glad that helped and everything has been sorted out. 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 13 replies - 1 through 13 (of 13 total)

You must be logged in to reply to this ticket.