Hello,
We apologize for the issue you are facing with the code to remove products from the shop page. The code you provided is attempting to unset the ‘Product’ schema, but it may not be structured correctly for your needs.
To remove all Schema from product category pages, you can use the following alternative code snippet:
/**
* Filter to remove all Schema from product category pages
*/
add_filter('rank_math/json_ld', function ($data, $jsonld) {
if (is_shop()) {
return [];
}
return $data;
}, 99, 2);
This code will effectively remove all Schema data from the shop page. Make sure to add this code to your rank-math.php file as you did before.
If you have any further questions or need additional assistance, please feel free to reply to this ticket, and a human agent from our support team will be happy to help you further. Thank you for raising this concern!
Sources:
Remove All Schema from Product Category Pages » Rank Math
This is an automated reply from Rank Math Support Bot. Your ticket has been assigned to a human agent and we will get back to you shortly.
I would prefer to keep the other snippets as they are useful collection snippets.
How can I remove only the product data.
Everything I have tries does not work.
Hello,
Thank you so much for getting in touch.
Please try this instead:
add_filter('rank_math/json_ld', function ($data, $jsonld) {
foreach ($data as $key => $schema) {
if( (is_front_page() || is_shop()) && 'Product' === $schema['@type'] ) {
unset( $data[ $key ] );
}
}
return $data;
}, 99, 2);
You can also try this code:
add_filter( "rank_math/snippet/rich_snippet_product_entity", function( $entity ) {
if( is_front_page() || is_shop() ) {
return false;
}
return $entity;
});
Let us know how that goes. Looking forward to helping you.
Instead of editing the Rank Math core file, hook the filter from your theme’s functions.php or a custom plugin and target the schema array more defensively. Rank Math often outputs Product schema as part of a graph, so you may need to loop through $data[‘@graph’] and unset items where @type is Product, rather than checking $data[‘Product’] directly.
Hello @danny-5372,
Thank you for reaching out to us.
Yes, Rank Math outputs schema in a graph format, so checking $data['Product'] directly won’t work in most cases. Looping through the @graph array and unsetting items where @type is Product is indeed the more reliable and defensive approach, and it should be done via a hook in functions.php or a custom plugin (not by editing core files).
Appreciate you sharing this clarification.
Don’t hesitate to get in touch with us if you have any other questions.