Hello,
Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.
Please add below filter code in your theme’s functions.php file to add brand valud on Product archive pages:
add_action( 'rank_math/json_ld', function( $data, $json_ld ) {
if ( isset( $data['ProductsPage'] ) ) {
foreach ( $data['ProductsPage']['@graph'] as $key => $product ) {
$data['ProductsPage']['@graph'][$key]['brand'] = 'Test Brand';
}
}
return $data;
}, 15, 2 );
Although as per the Google norms you should only include the data in snippet which exists on the page:
The structured data on the page should describe the content of that page. You should not create blank or empty pages just to hold structured data; nor should you add structured data about information that is not visible to the user, even if the information is accurate.
So instead of adding brand value to Products on archive pages I would suggest you to remove the Product snippet from arhcive pages since it is irrelevant and not needed. In the upcoming update of the Plugin, we’ve added an option in Settings to remove Prdouct snippet from archive pages as it is recommended by Google not having Product snippet on archive pages. For now, you can use below filter code to remove the Product snippet from archive pages:
add_action( 'rank_math/json_ld', function( $data, $json_ld ) {
if ( isset( $data['ProductsPage'] ) ) {
unset( $data['ProductsPage'] );
}
return $data;
}, 15, 2 );
Hope that helps. Thank you.
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.
hi,
Is there anyway to replace some of generated attribute data in json+ld data.
Let me know.
Hello,
Thank you for contacting Rank Math today.
Yes this is possible, you can use the following filter to modify posts schema data:
/**
* Filter to Short-circuit Schema if a 3rd party is interested in generating their own data.
* Replace $schmea_type with schema name like article, review, etc.
* @param array $entity Snippet Data
* @return array
*/
add_filter( "rank_math/snippet/rich_snippet_{$schema_type}", function( $entity ) {
return $entity;
});
Looking forward to helping you. Thank you.